Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 18th, 2006, 3:50 PM   #1
tbohon
Newbie
 
Join Date: Mar 2006
Location: Olympia WA USA
Posts: 11
Rep Power: 0 tbohon is an unknown quantity at this point
Date Routine

This may be old news to some but at the same time may be of value to someone else.

I was recently faced with creating a date stamp for the previous day's date. Using some hints found online, I concocted the following routine which works nicely:



### function to build dstamp (date stamp for previous day's date)

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time - 86400);

$mon = $mon + 1;
$year = $year + 1900;

$dstamp = sprintf "%04d%02d%02d", $year, $mon, $mday;

### end of dstamp function



The nice thing is that the value 86400 in the call to 'localtime' is equivalent to one (1) day ... so, by adjusting this value, you can create the same sort of date stamp (format is YYYYMMDD) for any offset.

Enjoy!

Tom
__________________
My mind is like a steel whatchamacallit ...
tbohon is offline   Reply With Quote
Old Jan 15th, 2007, 10:22 AM   #2
chrisranjana.com
Newbie
 
Join Date: Jan 2007
Location: Chennai India
Posts: 2
Rep Power: 0 chrisranjana.com is on a distinguished road
Will it take into account Daylight Savings time too ?

suppose yesterday was NON DST and today is a DST ?
__________________
Chris, Director, Chrisranjana.com
Web Developers and Software programmers
chrisranjana.com is offline   Reply With Quote
Old Jan 15th, 2007, 11:14 AM   #3
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Subtracting 86400 from the time will work most of the time, but not all of the time. If you need accuracy, use a module like DateTime:

perl Syntax (Toggle Plain Text)
  1. use DateTime;
  2. my $yesterday = DateTime->now->subtract( days => 1 );
Arevos is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
converting string to float beginnerCCC C 22 Oct 2nd, 2006 11:59 PM
Creation date comparison for subdirectories randum77 Visual Basic .NET 6 Jul 22nd, 2006 8:40 AM
Php Postgresql Class Pizentios Show Off Your Open Source Projects 15 Jun 28th, 2005 9:55 AM
Date Method Abyss Java 2 Apr 10th, 2005 8:47 AM
Enquiry About Visual Basic Project kbkhoo5053 Visual Basic 13 Feb 15th, 2005 2:20 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:45 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC