Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Comparing 2 DATETIME's - how to?

Quote Reply
Comparing 2 DATETIME's - how to?
Hi

I've got 2 DATETIME vars out of mysql in the following format...

%yyyy%-%mm%-%dd% %HH%:%MM%:%ss% 1999-03-25 21:32:02

Can anyone tell me how I can compare the two? What I want to do is find out if one datetime is before or after the other.

I have tried GT's date module with date_is_smaller() but it doesn't seem to recognise the hour, minute, second part of the date - only the actual date part of it.

Any ideas?

Thanks
r
Quote Reply
Re: [ryel01] Comparing 2 DATETIME's - how to? In reply to
As per the documentation in LSQL (Help > GT Module Documentation > GT > Date);

Code:
my $halloween = '2000-10-31';
my $christmas = '2000-12-25';
if (date_is_smaller($halloween, $christmas)) {
print "Halloween comes before christmas!";
}
if (date_is_greater($christmas, $halloween)) {
print "Yup, christmas comes after halloween.";
}
my @dates = ($halloween, $christmas);
print "Dates in order: ", sort date_comp @dates;

That should get you going :)

Basically, just set the date format with;

Code:
date_set_format(%yyyy%-%mm%-%dd% %HH%:%MM%:%ss%');

Hope that helps.

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Comparing 2 DATETIME's - how to? In reply to
hi andy

hmmm.... doesn't seem to recognise any change in the hour minute second fields, only the actual date part, even after setting the date format.

r
Quote Reply
Re: [Andy] Comparing 2 DATETIME's - how to? In reply to
You were right - got it to work. Smile

r