Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 7th, 2001, 11:37 AM
Matt M Matt M is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Posts: 2 Matt M User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.


Reply With Quote
  #2  
Old February 7th, 2001, 03:20 PM
mickalo's Avatar
mickalo mickalo is offline
Ole` Timer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: N.W. Iowa
Posts: 469 mickalo User rank is Private First Class (20 - 50 Reputation Level)mickalo User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 5 h 19 sec
Reputation Power: 8
Send a message via AIM to mickalo Send a message via MSN to mickalo
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!

Reply With Quote
  #3  
Old February 8th, 2001, 02:42 AM
Matt M Matt M is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Posts: 2 Matt M User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cool

Quote:
Originally posted by Matt M
All dates are in the dd/mm/yyyy format.

Reply With Quote
  #4  
Old February 8th, 2001, 07:33 AM
mickalo's Avatar
mickalo mickalo is offline
Ole` Timer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: N.W. Iowa
Posts: 469 mickalo User rank is Private First Class (20 - 50 Reputation Level)mickalo User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 5 h 19 sec
Reputation Power: 8
Send a message via AIM to mickalo Send a message via MSN to mickalo
Wink Ya got your work cut for ya!

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]

Reply With Quote
  #5  
Old February 8th, 2001, 08:00 AM
oakish oakish is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: Cleveland, Oh
Posts: 0 oakish User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #6  
Old February 8th, 2001, 08:05 AM
Matt M Matt M is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Posts: 2 Matt M User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #7  
Old February 8th, 2001, 08:26 AM
mickalo's Avatar
mickalo mickalo is offline
Ole` Timer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: N.W. Iowa
Posts: 469 mickalo User rank is Private First Class (20 - 50 Reputation Level)mickalo User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 5 h 19 sec
Reputation Power: 8
Send a message via AIM to mickalo Send a message via MSN to mickalo
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]

Reply With Quote
  #8  
Old February 10th, 2001, 08:30 PM
Adrian2 Adrian2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Location: London, England
Posts: 251 Adrian2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > date comparison (the three ghosts)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway