Page 1 of 1

i want to compare two datetimes

Posted: Sun Jul 05, 2009 10:15 pm
by lokesh_kumar_s
hi i want to compare two datetimes how can i do it

ex:
compare(2009-06-24 17:15:00,today's date)
i.e., compare 2009-06-24 17:15:00 with todays date please specify how to do it.
in php

Re: i want to compare two datetimes

Posted: Sun Jul 05, 2009 10:42 pm
by requinix
How about you specify what it is you want to do. In complete, coherent sentences.

Re: i want to compare two datetimes

Posted: Sun Jul 05, 2009 10:44 pm
by lokesh_kumar_s
tasairis wrote:How about you specify what it is you want to do. In complete, coherent sentences.
is there any way to compare two datetime objects

Re: i want to compare two datetimes

Posted: Mon Jul 06, 2009 12:18 am
by requinix
They aren't objects.

Compare how? The difference between the two? Measured how? Whether one is before the other? Are they in the same format?

Re: i want to compare two datetimes

Posted: Mon Jul 06, 2009 1:36 am
by lokesh_kumar_s
tasairis wrote:They aren't objects.

Compare how? The difference between the two? Measured how? Whether one is before the other? Are they in the same format?
Compare how?
ans:which one is ancient(older)
Are they in the same format?
ans:yes they are in the same format

Re: i want to compare two datetimes

Posted: Mon Jul 06, 2009 12:32 pm
by califdon
Datetimes are simply numbers (of seconds since some base date), so you can compare them or operate on them just like any other numbers. To find the difference between 2 datetimes, just subtract them. Remember, they are in seconds, so you may want to divide them by 60 (minutes) or 60*60 (hours) or 60*60*24 (days), etc.

Re: i want to compare two datetimes

Posted: Mon Jul 06, 2009 9:56 pm
by Eric!
Or in mysql:

Code: Select all

Select * From table where yourdate > '2009-07-01 12:00:00'
Gets everything after 2009-07-01 12:00:00.

Re: i want to compare two datetimes

Posted: Mon Jul 06, 2009 9:59 pm
by lokesh_kumar_s
Eric! wrote:Or in mysql:

Code: Select all

Select * From table where yourdate > '2009-07-01 12:00:00'
Gets everything after 2009-07-01 12:00:00.
can i use compare oprators in php for comparing datetimes

Re: i want to compare two datetimes

Posted: Mon Jul 06, 2009 10:18 pm
by Eric!
lokesh_kumar_s wrote: can i use compare oprators in php for comparing datetimes
I would convert the string to a time stamp integer and compare them.

Code: Select all

$time = "2005-04-03 12:34:56";
$timestamp = strtotime($time);
http://php.net/manual/en/function.strtotime.php