If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Create filename with date and time

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-04-04, 11:50
dbforums_ajayp dbforums_ajayp is offline
Registered User
 
Join Date: Feb 2004
Posts: 11
Question Create filename with date and time

How can I create a file in unix (csh) with date and time ?

File format : <filename>_<date>_<time>.txt

<date> - DDMMYY
<time> - HH24MISS
__________________
Regards,

Ajay Patel
Reply With Quote
  #2 (permalink)  
Old 02-04-04, 13:10
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
For example :

Code:
touch ${filename}_`date +'%d%m%Y_%H%M%S'`
__________________
Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 02-04-04, 13:12
thetank thetank is offline
Registered User
 
Join Date: Feb 2004
Posts: 1
Cool Re: Create filename with date and time

Quote:
Originally posted by dbforums_ajayp
How can I create a file in unix (csh) with date and time ?

File format : <filename>_<date>_<time>.txt

<date> - DDMMYY
<time> - HH24MISS
Hi. In AIX you can use some modifiers with date command in order to format the date result and extract only the useful info.
The command should be:
date +%<Field Descriptor>

For example, try this one:
touch filetest_`date +%d``date +%m``date +%y`_`date +%H``date +%M``date +%S`.txt

It must create an empty file with the name as you wish.

I include a list of the modifiers you can use
I hope it would be useful to you.
Regards

==============================================


Field Descriptors
%a Displays the locale's abbreviated weekday name.
%A Displays the locale's full weekday name.
%b Displays the locale's abbreviated month name.
%B Displays the locale's full month name.
%c Displays the locale's appropriate date and time representation. This is the default.
%C Displays the century as a decimal number (00-99). A year is divided by 100 and truncated to an integer.
%d Displays the day of the month as a decimal number (01-31). In a two-digit field, a 0 is used as leading space fill.
%D Displays the date in the format equivalent to %m/%d/%y.
%e Displays the day of the month as a decimal number (1-31). In a two-digit field, a blank space is used as leading space fill.
%h Displays the locale's abbreviated month name (a synonym for %b).
%H Displays the hour (24-hour clock) as a decimal number (00-23).
%I Displays the hour (12-hour clock) as a decimal number (01-12).
%j Displays the day of year as a decimal number (001-366).
%m Displays the month of year as a decimal number (01-12).
%M Displays the minutes as a decimal number (00-59).
%n Inserts a <new-line> character.
%p Displays the locale's equivalent of either AM or PM.
%r Displays 12-hour clock time (01-12) using the AM-PM notation; in the POSIX locale, this is equivalent to %I:%M:%S %p.
%S Displays the seconds as a decimal number (00- 59).
%t Inserts a <tab> character.
%T Displays the 24-hour clock (00-23) in the format equivalent to HH:MMS .
%u Displays the weekday as a decimal number from 1-7 (Sunday = 7). Refer to the %w field descriptor.
%U Displays week of the year(Sunday as the first day of the week) as a decimal number[00 - 53] . All days in a new year preceding the first Sunday are considered to be in week 0.
%V Displays the week of the year as a decimal number from 01-53 (Monday is used as the first day of the week). If the week containing January 1 has four or more days in the new year, then it is considered week 01; otherwise, it is week 53 of the previous year.
%w Displays the weekday as a decimal number from 0-6 (Sunday = 0). Refer to the %u field descriptor.
%W Displays the week number of the year as a decimal number (00-53) counting Monday as the first day of the week.
%x Displays the locale's appropriate date representation.
%X Displays the locale's appropriate time representation.
%y Displays the last two numbers of the year (00-99).
%Y Displays the year with century as a decimal number.
%Z Displays the time-zone name, or no characters if no time zone is determinable.
%% Displays a % (percent sign) character.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On