date time stamps in bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting date time stamps in bash
# 1  
Old 10-13-2012
date time stamps in bash

I'm looking for a way to have the "date" command output the date in a specific format.

I'm not familiar with the different ways to use the date command at all. i read up on it, but i dont get how to manipulate it.

i know that i can get the date format to give me a format like:

Code:
2012-10-13

by typing:

Code:
$(date +%Y-%m-%d)

but i'm clueless on how to do the same for date formats like the below? how do i include the time? and timezone (where shown below)?

Code:
2012/02/21 16:23:13 UTC 

[#|2012-02-21T17:17:39.495+0000

2012-02-21 16:34:43,897 

[Tue Feb 21 04:02:27 2012] 

Feb 21 14:00:53 

Wed Mar 28 15:46:21 2012  

<Mar 29, 2012 4:41:49 PM UTC> 

2012.02.24 19:08:47 

04/21/2012 05:00:21 PM 

120806 23:44:48 (year,month,day)

10/9/12 11:06:43:131 PDT

notice how for the date "10/9/12", the day of the month is "single digit". some date formats have "2" digits for the day of the month, as in "09" instead of "9". how can the date format be used to output the formats as is shown in all of the above?

OS: Linux / SunOS
bash
# 2  
Old 10-13-2012
man date shows the full list of format qualifiers including the following
Code:
       %:::z  numeric time zone with : to necessary precision (e.g., -04, +05:30)

       %Z     alphabetic time zone abbreviation (e.g., EDT)

This User Gave Thanks to Skrynesaver For This Post:
# 3  
Old 10-13-2012
Quote:
Originally Posted by Skrynesaver
man date shows the full list of format qualifiers including the following
Code:
       %:::z  numeric time zone with : to necessary precision (e.g., -04, +05:30)

       %Z     alphabetic time zone abbreviation (e.g., EDT)

can you please give examples by using the date command to output the formats in my original post?
# 4  
Old 10-13-2012
Code:
~/$ date +"%Y/%m/%d %H:%M:%S %Z"
2012/10/13 16:51:50 IST
~/$ date +"[#|%Y/%m/%dT%H:%M:%S %Z"
[#|2012/10/13T16:53:43 IST
~/$ date -u +"%Y/%m/%dT%H:%M:%S %Z"
2012/02/21 16:23:13 UTC

Adjusting for the others should be possible from the examples above and the man page, hope that helps.

Last edited by Skrynesaver; 10-13-2012 at 01:16 PM..
This User Gave Thanks to Skrynesaver For This Post:
# 5  
Old 10-13-2012
Code:
~]$ TZ=PDT date +"%d/%m/%y %H:%M:%S:%s %Z"
13/10/12 16:23:40:1350145420 PDT

you may also can use TZ as time zone

Last edited by justbow; 10-13-2012 at 01:29 PM.. Reason: quote
This User Gave Thanks to justbow For This Post:
# 6  
Old 10-13-2012
thank you guys!

how about these formats:

Code:
<Mar 29, 2012 4:41:49 PM UTC>

Code:
120806 23:44:48

and

Code:
10/9/12 11:06:43:131 PDT

# 7  
Old 10-14-2012

Use the format specifiers to get whatever output you want. For example:
Code:
date +%y%m%d

See the man page for the full list of specifiers.
This User Gave Thanks to cfajohnson For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Cygwin_openssh time stamps

I've installed cygwin_openssh on Windows 2012 R2 and it's working great. My issue is when a file is uploaded say from a different timezone, when it is uploaded, it doesnt pick up the sftp servers time.. Is there a way to fix that? i.e. When someone in PST uploads a file to this server in EST,... (0 Replies)
Discussion started by: MikeAdkins
0 Replies

2. Shell Programming and Scripting

Controlling time stamps in a bash script

Hi, I have a bash script that generates CSV (.txt) files at fairly regular time intervals. I'm currently time stamping each batch of measurements at the time I write the rows into a MySQL database. As the result, one set of data might get the time 12:01:32 and the next set of data gets the time... (18 Replies)
Discussion started by: Zooma
18 Replies

3. Shell Programming and Scripting

How to get the Logs between two Time Stamps?

Hi, I have been working on the error Log script, where errors are pulled from server. I need to pull the data of the error logs between two dates & time, for example : 22/12/2014 20:00:00 22/12/2014 22:00:00 Whatever error have came during this duration. Now the question is the record... (6 Replies)
Discussion started by: amitgpta90
6 Replies

4. Shell Programming and Scripting

Increment time stamps.

Hi Gents. Please can you help me to solve a problem. I have a long list of files, which I need to change the time stamp. -r--r--r-- 1 geo2 geovect 47096216 Feb 8 10:40 00000009.segd -r--r--r-- 1 geo2 geovect 47096216 Feb 8 10:40 00000010.segd -r--r--r-- 1 geo2 geovect 47096216 Feb ... (11 Replies)
Discussion started by: jiam912
11 Replies

5. Shell Programming and Scripting

Time difference between two time stamps

Hi Friends, I have 2 varaibles which contain START=`date '+ %m/%d/%y %H:%M:%S'` END=`date '+ %m/%d/%y %H:%M:%S'` i want the time difference between the two variables in Seconds. Plz help. (2 Replies)
Discussion started by: i150371485
2 Replies

6. Homework & Coursework Questions

Date comparison with 'string date having slashes and time zone' in Bash only

1. The problem statement, all variables and given/known data: I have standard web server log file. It contains different columns (like IP address, request result code, request type etc) including a date column with the format . I have developed a log analysis command line utility that displays... (1 Reply)
Discussion started by: TariqYousaf
1 Replies

7. Shell Programming and Scripting

comparing time stamps

Hello All, I'm generating timestamps (file creation timestamps) for all the files in a directory. I need to compare all the timestamps. for example if i have 4 files and their timestamps are 20091125114556, 20091125114556,20091125114556,20091125114556 respectively. I need to differentiate... (9 Replies)
Discussion started by: RSC1985
9 Replies

8. UNIX for Dummies Questions & Answers

comparing time stamps

Hello All, I'm generating timestamps (file creation timestamps) for all the files in a directory. I need to compare all the timestamps. for example if i have 4 files and their timestamps are 20091125114556, 20091125114556,20091125114556,20091125114556 respectively. I need to differentiate... (1 Reply)
Discussion started by: RSC1985
1 Replies

9. UNIX for Dummies Questions & Answers

Adding Date & time stamps to filename

I need to edit the file name with date and time while writing the script. please help. (1 Reply)
Discussion started by: manish.s
1 Replies

10. UNIX for Dummies Questions & Answers

List files with date and time stamps only

Hi there, I'm using terminal on mac and using the ls -l command to list all the files in a directory. However, I only want to display the date and time stamp of each file rather than permissions, owner, group etc... Is this possible? Many thanks in advance Dave (2 Replies)
Discussion started by: davewg
2 Replies
Login or Register to Ask a Question