473,320 Members | 1,933 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,320 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 1707
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.