Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i compare a date i have saved, with the system date? 3

Status
Not open for further replies.

wyatt

Programmer
Aug 11, 2000
3
US
any help would be nice.
 
Hi Wyatt,<br><br>I'm sure there're more elegant ways of doing this (and I'm probably about to hear about 8 of them &lt;grin&gt;) but I have a real lazy way of doing this in Perl.<br><br>Save dates as datetime strings in the format 'YYYYMMDDHHMISS' with the HH in 24hr clock.<br><br>You can then sort data by them, comparisons work as you would expect and you can get just the date portion like this:<br><br>$date = substr($datetimevar,0,6);<br><br>and the time portion like this:<br><br>$time = substr($datetimevar,7,6);<br><br>So - get the current time with localtime(time) and build a string with the same format as your saved dates. <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
&lt;being more specific&gt;<br><br>i can sort the dates just fine.&nbsp;&nbsp;what i need is to compare them for the purpose of evaluating there difference.&nbsp;&nbsp;for example, is my saved date 30 days old? 90 days old?&nbsp;&nbsp;and so on.&nbsp;&nbsp;i can do this in javascript and vbscript with a simple function call.
 
I have found taken to leaving the date in seconds since january 1, 1970 as supplied by 'time'.<br><br>That way data comparisons, subtraction, etc is extremely simple.&nbsp;&nbsp;If wanted to see if the saved date was older that 30 days, <br><br>1 - read $saved date from file <br>2 - get current date with '$date = time;'<br>3 - how many seconds in 30 days - $month = ( 60sec x 60min x 24hr x 30days)<br>4 - if ($date - $month &gt; $saved) { do something; } <br><br>maybe this helps?? <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
There're some modules on CPAN that do date manipulation as well. <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
use Date::Manip;<br><br>@time = localtime(time) gives you the broken down info<br>$time = &UnixDate(@time) gives you the epoch seconds<br><br>If you store &UnixDate(@your_time), you can compare it to the time variable which gives you current epoch seconds <p> Sincerely,<br><a href=mailto: > </a><br><a href= Anderson</a><br>CEO, Order amid Chaos, Inc.<br>
 
i have a question :
can i compare the date using this statement
if ($time == $localtime) {
print &quot;date match\n&quot;;
}

please someone help me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top