473,395 Members | 1,649 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Unix Date Help

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 simple unix command solution?

Any ideas,

Thanks
Feb 14 '08 #1
2 1710
Here's a Perl solution if you can't find anything simpler. You'll need to download the Time::Piece and Time::Seconds modules from CPAN.

Expand|Select|Wrap|Line Numbers
  1. use warnings;
  2. use strict;
  3. use Time::Piece;
  4. use Time::Seconds;
  5.  
  6. &init;
  7.  
  8. sub init
  9. {
  10.    my $today      = localtime();
  11.    my $days_ahead = 1;
  12.    my $date       = &get_days_ahead ( $today, $days_ahead );
  13.  
  14.    print "$date\n";
  15. }
  16.  
  17. sub get_days_ahead
  18. {
  19.    my ( $date, $days ) = @_;
  20.  
  21.    for ( my $i = 0; $i < $days; $i++ )
  22.    {
  23.       $date += ONE_DAY;
  24.    }
  25.  
  26.    return ( &get_mmddyy ( $date ) );
  27. }
  28.  
  29. sub get_mmddyy
  30. {
  31.    my ( $date ) = @_;
  32.    my ( $weekday, $month, $day, $time, $year ) = split ( / +/, uc ( $date ) );
  33.  
  34.    if    ( $month eq "JAN" ) { $month = "01"; }
  35.    elsif ( $month eq "FEB" ) { $month = "02"; }
  36.    elsif ( $month eq "MAR" ) { $month = "03"; }
  37.    elsif ( $month eq "APR" ) { $month = "04"; }
  38.    elsif ( $month eq "MAY" ) { $month = "05"; }
  39.    elsif ( $month eq "JUN" ) { $month = "06"; }
  40.    elsif ( $month eq "JUL" ) { $month = "07"; }
  41.    elsif ( $month eq "AUG" ) { $month = "08"; }
  42.    elsif ( $month eq "SEP" ) { $month = "09"; }
  43.    elsif ( $month eq "OCT" ) { $month = "10"; }
  44.    elsif ( $month eq "NOV" ) { $month = "11"; }
  45.    elsif ( $month eq "DEC" ) { $month = "12"; }
  46.  
  47.    if ( length ( $day ) == 1 ) { $day = "0" . $day; }
  48.    $year = substr ( $year, 2 );
  49.  
  50.    return ( "$month/$day/$year" );
  51. }
Feb 14 '08 #2
ghostdog74
511 Expert 256MB
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 simple unix command solution?

Any ideas,

Thanks
if you have GNU date
Expand|Select|Wrap|Line Numbers
  1. # date +%Y/%m/%d -d "1 day"
  2. 2008/02/16
  3.  
  4.  
Feb 15 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: todd | last post by:
i have a site that displays shows. i am getting my date from a mysql function "CURDATE()" but it give me the date one day ahead of the actual date. i tried $myrow -1 but that doen't work. im sure...
0
by: Andy Jackman | last post by:
Hi, 1) I was investigating the unix_timestamp routine in mysql (version 3.23.46-nt) and for some reason the unix epoch (1-1-1970) was returned with a value of -3600. Then, as you can see, it...
1
by: MLH | last post by:
In an Access 97 form, I have a textbox control with the following code that runs AfterUpdate... Option Compare Database Option Explicit Private Sub UNIXdate_AfterUpdate() Me!RealDate =...
2
by: Dan Jacobson | last post by:
Let's say you don't have any more documentation than man pages, and you want to figure out how to do the equivalent of $ date in C. I.e. just simply print out the current date and time. How to...
16
by: kinane3 | last post by:
I'm been using dev environments like Dreamweaver with ASP for years and recently got a php job that requires SSH to access the server. Command line is really new to me and I need to learn this. ...
1
by: ashmatusunrai | last post by:
I have to write a unix shell script, and I've done most of it but I can't figure out one part. I need to write every line containing the word ``delete'' produced by ``man mail'' into a file called...
1
by: Karim | last post by:
Hi, I am working on a c++ project involving sockets and threads and I need to ask a pretty basic question. If you have a socket that every time it accepts a connection (accept()) it spawns a...
1
by: heckstein | last post by:
I am running a query in Access 2003 to pull training courses with a start date that falls within a specified date span such 2/1/07 to 2/28/07. I was using this code - (( I.STARTDATE) Between...
8
by: saladinator | last post by:
I have created an Excel spreadsheet that has a lot of data. What I want to do is import the spreedsheet to Access and create a form so that I can print each row per page in a proffessional manner....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.