Generate last hour date in YYYYmmddHH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Generate last hour date in YYYYmmddHH
# 1  
Old 03-14-2011
Generate last hour date in YYYYmmddHH

can some one show me how to generate last hour of date for example:
2012010100 -> 2011123123 // check first date of a new year
2008030100 -> 2008022923 // check leap year as well
And also no perl code is restricted.
This is what i am facing issue now, can someone provides help to me.

Last edited by alvin0618; 03-14-2011 at 11:49 PM..
# 2  
Old 03-15-2011
Got gawk?
Code:
$ echo "2012 01 01 00"|gawk '{print strftime("%Y %m %d %H", mktime($0 " 00 00") - (60 * 60))}'
2011 12 31 23

$ echo "2008 03 01 00"|gawk '{print strftime("%Y %m %d %H", mktime($0 " 00 00") - (60 * 60))}'
2008 02 29 23

# 3  
Old 03-15-2011
Quote:
Originally Posted by Ygor
Got gawk?
Code:
$ echo "2012 01 01 00"|gawk '{print strftime("%Y %m %d %H", mktime($0 " 00 00") - (60 * 60))}'
2011 12 31 23

$ echo "2008 03 01 00"|gawk '{print strftime("%Y %m %d %H", mktime($0 " 00 00") - (60 * 60))}'
2008 02 29 23

Can the date get from current date from system ?
# 4  
Old 03-15-2011
Yup...
Code:
$ gawk 'BEGIN{print strftime("%Y %m %d %H", systime() - (60 * 60))}'
2011 03 15 15

# 5  
Old 03-15-2011
Quote:
Originally Posted by Ygor
Yup...
Code:
$ gawk 'BEGIN{print strftime("%Y %m %d %H", systime() - (60 * 60))}'
2011 03 15 15

I need crossover others platform between GNC and Suns. Suns can't run this code. Do you have other solution? Kindly appreciate your reply. TQ
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Day/Hour diff between two date

Dear All I need to find out day diff between two dates. date -d or date -- day is not working in mine system. Currently i am using below code but it gives me wrong value while month change. IP: Date 1: 20150802 11:30:45 Date 2: 20150728 16:30:45 code used: awk '{t1=$2; t2=$4;... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

2. Solaris

Solaris 9 Zone : Date command in crontab shows delayed(One Hour) output

SOLARIS 9 Zone : date command in crontab shows delayed(One Hour) output Hi folks, the date command shows the correct date and time, How ever, if the date command executed through crontab in any form of scrip the output shows as one hour delayed, similar to date -u.. Can some one help in... (12 Replies)
Discussion started by: judi
12 Replies

3. UNIX for Advanced & Expert Users

Finding/Grep on files with date and hour in the file name

Hi, I have a folder structure as follows, DATA -> 2012-01-01 -> 00 -> ABC_2012-01-03_00.txt -> 01 -> ABC_2012-01-03_01.txt -> 02 -> ABC_2012-01-03_02.txt ... -> 23 -> ABC_2012-01-03_02.txt -> 2012-01-02 ... (1 Reply)
Discussion started by: mihirvora16
1 Replies

4. Shell Programming and Scripting

Finding/Grep on files with date and hour in the file name

Hi, I have a folder structure as follows, DATA -> 2012-01-01 -> 00 -> ABC_2012-01-03_00.txt -> 01 -> ABC_2012-01-03_01.txt -> 02 -> ABC_2012-01-03_02.txt ... -> 23 -> ABC_2012-01-03_02.txt -> 2012-01-02 -> 2012-01-03 So the dir DATA contains the above hierarchy, User input Start and... (6 Replies)
Discussion started by: mihirvora16
6 Replies

5. Shell Programming and Scripting

Generate quarter dates with begin date and end date

Hi All, I am trying to generate quarter dates with user giving input as begin date and end date. Example: Input by user: begin_date = "2009-01-01" end_date = 2010-04-30" required output: 2009-01-01 2009-03-31 09Q01 2009-04-01 2009-06-30 09Q02 . . till 2010-01-01 2010-03-31 10Q01 ... (9 Replies)
Discussion started by: sol_nov
9 Replies

6. Shell Programming and Scripting

Help to generate date from day of the year

Hi I want to convert the day of the year(yyyyddd) to date in mmddyy format Example: input is 2005029 --------> 29th day of 2005 I have to get the output as 01292005 ---> jan 29th 2005 I've to do this in K-Shell There were threads that dealt with coverting date to day of the year but I... (3 Replies)
Discussion started by: sudhamayeev
3 Replies

7. Shell Programming and Scripting

Compare file timestamp with current date. Diff must be 1 hour.

Hello, I've created the script below to compare the content of two files with a delay of an hour. After an hour, the lines that exist in both files, will be printed and executed. The script now uses a counter to countdown 50 minutes. But what I would prefer is to check the file timestamp of... (3 Replies)
Discussion started by: taipan
3 Replies

8. Shell Programming and Scripting

Unix Script for getting date and validating just Hour

Hi, Can someone guide me to write a unix script for getting a hour out of a date command and validating hour to see if its > 7 and < 16. if hours is >7 and <16 then assign a variable value of 0730 and if hour is >16 then assign a variable value of 1630? Help appreciated. Thanks in advance.... (9 Replies)
Discussion started by: zulfikarmd
9 Replies

9. Shell Programming and Scripting

Get date and time for past 1 hour from current date

Hi, I need to get the date and time for past 1 hour from the current date. Anyone know how to do so? Thanks (5 Replies)
Discussion started by: spch2o
5 Replies

10. Shell Programming and Scripting

generate rows from date.

Hi I have file like below has many rows with different dates and ids. ID FIRST_DT SEC_DT 111 2005-10-02 2010-10-01 222 2007-11-01 2040-09-13 I need to generate rows first_dt increment + 1 year until the SEC_DT year matches ,ID and sec_dt stays same ,here... (14 Replies)
Discussion started by: GrepMe
14 Replies
Login or Register to Ask a Question