UNIX Dates


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers UNIX Dates
# 1  
Old 02-14-2008
UNIX Dates

Hey guys.

I need to manipulate the system date to move forward a day. So, if the system date was 02/14/08, I need the 'new' date to be 02/15/08 so my script will look for the date of 02/15/08. The thing is the file I will be looking for always has the date of the next day.

Any ideas,

Thanks
# 2  
Old 02-14-2008
No, you probably don't want to set the system time to any arbitrary value. Even with your own desktop, it may cause problems you will not anticipate.


From what I gather from what you said, all you need to do is use touch -t <file>:
Code:
# assuming tomorrow is feb 15 2008 at 1200

# if myfile doesn't exist touch wil create an empty file for you
touch -t 200802151200 myfile

Now the file has tomoorow's date.
# 3  
Old 02-14-2008
In ksh or bash

Current time:
XXX$ date
Thu Feb 14 19:20:44 CET 2008

Same time tomorrow:
XXX$ ZONE=`date +%Z`
XXX$ TZOFFSET=`date +%z| sed -e "s/..$//"`
XXX$ ((DAYAHEAD=$TZOFFSET+24))
XXX$ TZ=$ZONE-$DAYAHEAD date
Fri Feb 15 19:20:44 CET 2008
# 4  
Old 02-14-2008
You can set an enviroment variable for tomorrow's date and then use
that for your check.

Code:
date +%Y%m%d
20080214

TOMORROW=`TZ=aaa-24 date +%Y%m%d`

echo $TOMORROW
20080215

# 5  
Old 02-14-2008
thanks den for your help. Simple solution.

One more thing though, I need a way to find out what day of the week a certain date is.

For example, if the date returned by what den posted, 20080215, the day of week would be '5'.

Does anybody know a way to find this information?

Thanks again, appreciate your help
# 6  
Old 02-14-2008
date +%u

gives the day of the week as a number
# 7  
Old 02-14-2008
Quote:
Originally Posted by denn
You can set an enviroment variable for tomorrow's date and then use
that for your check.

Code:
date +%Y%m%d
20080214

TOMORROW=`TZ=aaa-24 date +%Y%m%d`

echo $TOMORROW
20080215

This works fine if you are not interested in hours and minutes, because it neglects your offset to UTC. It will also specify the timezone as aaa.

To maintain all information, and just go 1 day ahead, the example as I posted is correct.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Files between two dates in UNIX

Hi Team, I need to connect to a prod server and need to get the files which falls between two dates. I should not create ant files on that machine. I am using korn shell. Your help is very much appreciated. Vinay (13 Replies)
Discussion started by: gvkumar25
13 Replies

2. UNIX for Advanced & Expert Users

How to get the Missing dates between two dates in the table?

Hi Am Using Unix Ksh ... I have a Table called date select * from date ; Date 01/02/2013 06/02/2013 I need the output as Missing Date 01/02/2013 02/02/2013 03/02/2013 04/02/2013 05/02/2013 06/02/2013 (2 Replies)
Discussion started by: Venkatesh1
2 Replies

3. UNIX for Dummies Questions & Answers

How to write the dates between 2 dates into a file

Hi All, I am trying to print the dates that falls between 2 date variables into a file. Here is the example. $BUS_DATE =20120616 $SUB_DATE=20120613 Output to file abc.txt should be : 20120613,20120614,120120615,20120616 Can you pls help me accomplish this in LINUX. Thanks... (5 Replies)
Discussion started by: dsfreddie
5 Replies

4. Emergency UNIX and Linux Support

Replacing dates]] with (dates)]]

Hi guys, For my wiki site I need to fix 1400 pages that use the wrong date format, most pages (not all) use eg. 1988]] I need to change that to (1988)]] The date range goes back to 1400 so I guess I need to do the following ssh into my server, dump mysql database vi .sql dump search... (20 Replies)
Discussion started by: lawstudent
20 Replies

5. Programming

SQL: find if a set od dates falls in another set of dates

Don't know if it is important: Debian Linux / MySQL 5.1 I have a table: media_id int(8) group_id int(8) type_id int(8) expiration date start date cust_id int(8) num_runs int(8) preferred_time int(8) edit_date timestamp ON UPDATE CURRENT_TIMESTAMP id... (0 Replies)
Discussion started by: vertical98
0 Replies

6. Shell Programming and Scripting

Compare 2 dates in unix

I have 2 variables in my script like this $v_last_update_date1 = 08/18/2009 08:41:17 $v_last_update_date2 = 08/18/2009 08:30:17 Now I want to comapre with greater than if then go forward else error and exit out I am getting unknown test operator error Can anyone advise (1 Reply)
Discussion started by: veeru
1 Replies

7. Shell Programming and Scripting

Need script to generate all the dates in DDMMYY format between 2 dates

Hello friends, I am looking for a script or method that can display all the dates between any 2 given dates. Input: Date 1 290109 Date 2 010209 Output: 300109 310109 Please help me. Thanks. :):confused: (2 Replies)
Discussion started by: frozensmilz
2 Replies

8. UNIX for Advanced & Expert Users

Select entries between two dates by converting Unix timestamp in Oracle Database.

Hi, I need to select the entries between two dates from an Oracle db. The Oracle db has a column with Unix timestamps. I use the following querry, but it doesnt seem to be working as desired. select count(*) from reporter_status where to_char(FIRSTOCCURRENCE, 'mm-dd-yy') between ('08-07-06')... (1 Reply)
Discussion started by: amitsayshii
1 Replies

9. UNIX for Dummies Questions & Answers

Need help with Unix dates

I'm very new to Unix, so forgive me for what will probably be a very quick fix. I have the following in a ksh script. Its purpose is to return yesterday's date. The $DAY part is coming back with a '2' but I need it to return as '02'. How can I do that? date '+%b %d %Y' | { read MONTH DAY... (4 Replies)
Discussion started by: ssmiths001
4 Replies

10. UNIX for Dummies Questions & Answers

Unix dates

How can I use the date function to get the following format? Nov 18 I've tried date +%b%d but I get it in this format: Nov18 with no space. (1 Reply)
Discussion started by: ssmiths001
1 Replies
Login or Register to Ask a Question