i want to compare two datetimes
Moderator: General Moderators
-
lokesh_kumar_s
- Forum Commoner
- Posts: 48
- Joined: Mon Apr 13, 2009 5:39 am
- Contact:
i want to compare two datetimes
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
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
How about you specify what it is you want to do. In complete, coherent sentences.
-
lokesh_kumar_s
- Forum Commoner
- Posts: 48
- Joined: Mon Apr 13, 2009 5:39 am
- Contact:
Re: i want to compare two datetimes
is there any way to compare two datetime objectstasairis wrote:How about you specify what it is you want to do. In complete, coherent sentences.
Re: i want to compare two datetimes
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? The difference between the two? Measured how? Whether one is before the other? Are they in the same format?
-
lokesh_kumar_s
- Forum Commoner
- Posts: 48
- Joined: Mon Apr 13, 2009 5:39 am
- Contact:
Re: i want to compare two datetimes
Compare how?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?
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
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
Or in mysql:
Gets everything after 2009-07-01 12:00:00.
Code: Select all
Select * From table where yourdate > '2009-07-01 12:00:00'-
lokesh_kumar_s
- Forum Commoner
- Posts: 48
- Joined: Mon Apr 13, 2009 5:39 am
- Contact:
Re: i want to compare two datetimes
can i use compare oprators in php for comparing datetimesEric! wrote:Or in mysql:
Gets everything after 2009-07-01 12:00:00.Code: Select all
Select * From table where yourdate > '2009-07-01 12:00:00'
Re: i want to compare two datetimes
I would convert the string to a time stamp integer and compare them.lokesh_kumar_s wrote: can i use compare oprators in php for comparing datetimes
Code: Select all
$time = "2005-04-03 12:34:56";
$timestamp = strtotime($time);