FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » comparing dates?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: comparing dates? [message #175544 is a reply to message #175485] Thu, 06 October 2011 09:00 Go to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma:
Senior Member
El 02/10/2011 15:00, Michael Joel escribió/wrote:
> Is there a better way to compare dates than breaking a date into day,
> month, year and comparing each part?
> I need to know if a date (say 10/03/2011) is before another date in
> the same format. Direct comparison doesn't work.

Doing maths with strings is normally complicated. PHP provides two
native formats to handle dates: Unix timestamps and DateTime objects.
Both allow direct comparison with the "<" operator.

var_dump(new DateTime('2011-03-10') < new DateTime('2011-03-31'));
var_dump(strtotime('2011-03-10') < strtotime('2011-03-31'));

bool(true)
bool(true)

Full reference can be found at
http://es2.php.net/manual/en/book.datetime.php

--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: simple image in PHP
Next Topic: Question about new lines
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 10 16:30:55 GMT 2024

Total time taken to generate the page: 0.07705 seconds