I'm trying to calculate date and time but I don't know the correct script to do that.
The way, which I'm using, is giving wrong result, so will you please help me.
This is the script, which I'm using, just to make the question clear
#!/usr/bin/perl
$olddate='10/2/2001';
$oldtime='10:05:43';
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time+$addsecs);
@months = ("1","2","3","4","5","6","7","8","9","10","11","12");
if ($sec < 10) {$sec = "0$sec";}
if ($min < 10) {$min = "0$min";}
if ($hour < 10) {$hour = "0$hour";}
if ($hour > 11) {$ap = "PM";}
if ($hour < 12) {$ap = "AM";}
if ($mday < 10) {$mday = "0$mday";}
$millyear = $year + 1900;
$date = "$mday/@months[$mon]/$millyear";
$time = "$hour:$min:$sec";
$date_different = $date - $olddate;
$time_different = $time - $oldtime;
print "Content-type: text/html\n\n";
print "Current date:$date Old Date:$olddate<br>\n";
print "Current time: $time Old time:$oldtime<br>\n";
print "Different between old date and new date: $date_different<br>\n";
print "Different between old time and new time: $time_different<br>\n";Well, I have a couple of suggestions for your script:
1. If you just assign the output of the localtime function to a scalar variable, you'll get a nice little formatted date/time like Monday September 10 11:45:10 pm 2001.
2. $date_different is the result of the subtraction of two strings, and I don't know what that will return, but I don't think that would produce anything very coherent.
These are the only two suggestions I have right now, but if you could explain a little more about how wrong the output is, maybe someone could figure out some more specifics.You will probably need to convert time and date into basic units then do the subtraction then convert back to the original time/date format. The basic unit for time is seconds and for date you can try converting to days (or use $yday) then convert back to month/day/year. Otherwise how can the script do the correct calculation?
What type of answer are you expecting for the difference between the dates? The difference in time is clear enough, so many hours-minutes-seconds, but the difference in dates is not so clear, the easiest difference would be the amount of days rounded off to the nearest whole day.
Maybe you could just use a free script like Matt Wrights countdown script <!-- m --><a class="postlink" href="http://www.worldwidemart.com/scripts/countdown.shtml">http://www.worldwidemart.com/scripts/countdown.shtml</a><!-- m -->
Or maybe someone else knows an easier way.....
Regards,
Kevin
The way, which I'm using, is giving wrong result, so will you please help me.
This is the script, which I'm using, just to make the question clear
#!/usr/bin/perl
$olddate='10/2/2001';
$oldtime='10:05:43';
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time+$addsecs);
@months = ("1","2","3","4","5","6","7","8","9","10","11","12");
if ($sec < 10) {$sec = "0$sec";}
if ($min < 10) {$min = "0$min";}
if ($hour < 10) {$hour = "0$hour";}
if ($hour > 11) {$ap = "PM";}
if ($hour < 12) {$ap = "AM";}
if ($mday < 10) {$mday = "0$mday";}
$millyear = $year + 1900;
$date = "$mday/@months[$mon]/$millyear";
$time = "$hour:$min:$sec";
$date_different = $date - $olddate;
$time_different = $time - $oldtime;
print "Content-type: text/html\n\n";
print "Current date:$date Old Date:$olddate<br>\n";
print "Current time: $time Old time:$oldtime<br>\n";
print "Different between old date and new date: $date_different<br>\n";
print "Different between old time and new time: $time_different<br>\n";Well, I have a couple of suggestions for your script:
1. If you just assign the output of the localtime function to a scalar variable, you'll get a nice little formatted date/time like Monday September 10 11:45:10 pm 2001.
2. $date_different is the result of the subtraction of two strings, and I don't know what that will return, but I don't think that would produce anything very coherent.
These are the only two suggestions I have right now, but if you could explain a little more about how wrong the output is, maybe someone could figure out some more specifics.You will probably need to convert time and date into basic units then do the subtraction then convert back to the original time/date format. The basic unit for time is seconds and for date you can try converting to days (or use $yday) then convert back to month/day/year. Otherwise how can the script do the correct calculation?
What type of answer are you expecting for the difference between the dates? The difference in time is clear enough, so many hours-minutes-seconds, but the difference in dates is not so clear, the easiest difference would be the amount of days rounded off to the nearest whole day.
Maybe you could just use a free script like Matt Wrights countdown script <!-- m --><a class="postlink" href="http://www.worldwidemart.com/scripts/countdown.shtml">http://www.worldwidemart.com/scripts/countdown.shtml</a><!-- m -->
Or maybe someone else knows an easier way.....
Regards,
Kevin