|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
just a quickie...
I need to calculate if a date is either before an events start date (future), after the events end date (past), or between the two (present). All dates are in the dd/mm/yyyy format. The only thing I can think of is pulling each date apart and comparing each bit. Surely there must be an easier way. Cheers for fears. |
|
#2
|
||||
|
||||
|
Are your start date and end dates in the same format:
dd/mm/yyyy ![]() Mickalo
__________________
Thunder Rain Internet Publishing Custom Programming & Database development Providing Personal/Business Internet Solutions that work! |
|
#3
|
|||
|
|||
|
Quote:
![]() |
|
#4
|
||||
|
||||
|
It's partically impossible to do any type of numerical date calculation when you have a date/time formatted like you have now. what you need to do is get the date into a workable format: YYYYMMDD. Then you can do you calculations. Example:
======================== Start Date: 20010101 End Date: 20010301 Todays Date: 20010207 ======================== Todays Date is greater then the Start Date and less then the End date, if you do a numerical comparsion. By treating the dates now as a numerical value. If you store your dates like this, then if you need to display the dates for some reason and you wante to display them as DD-MM-YYYY you will have to manipulate the dates somewhat in the same manner you would do to convert the dates to a numerical value. It involves quiet a bit of substitions substr() A suggestion. If you need to store dates and need to use this dates for calculations, store your dates in two formats. One for your normal display desired and the same one in a numerical format. Then you can pull either date for what ever you need to do. Another method, is using UN*X time() for date/time calculations. Which is exact to the second! Mickalo [Edited by mickalo on 02-08-2001 at 06:37 AM] |
|
#5
|
|||
|
|||
|
Time issue
Where theres time to burn theres a way...
use Time::Local; $time_1=timegm(0,0,0, split(/\//, $firstime_var)); $time_2=timegm(0,0,0, split(/\//, $secondtime_var)); $time_3=timegm(0,0,0, split(/\//, $thirdtime_var)); gives the seconds from 1970. oakish |
|
#6
|
|||
|
|||
|
Cheers guys.
I now have it working. Split the date from dd/mm/yyyy and then stick it back together as yyymmdd. From here the comparisons where dead easy. Thanks for the help mickalo; I had forgotten that you could compare dates in the yyyymmdd format. Somebody should really write a module for date and time manipulation and comparisons. |
|
#7
|
||||
|
||||
|
A quick method to convert your date: DD/MM/YYYY
Just do something like this: Code:
my $date = "08/02/2001"; my @newdate = split(/\//,$date); my $formate_date = "$newdate[2]" . "$newdate[1]" . "$newdate[0]"; Now the $formate_date equals: 20010208 Mickalo [Edited by mickalo on 02-08-2001 at 07:43 AM] |
|
#8
|
|||
|
|||
|
I must be bored:
Code:
$date = '31/05/2001';
$newdate = join("", reverse( $date =~ m#(\d{2})/(\d{2})/(\d{4})# ));
print $newdate;
There are those that believe that minimum legibility == maximum job security. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > date comparison (the three ghosts) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|