Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #3317
| From | "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: comparing dates? |
| Date | 2011-10-06 11:00 +0200 |
| Organization | http://alvaro.es/ |
| Message-ID | <j6jqmi$4d6$1@dont-email.me> (permalink) |
| References | <o2og875gpttj3c9h6ilv93mosd88dbujqt@4ax.com> |
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
--
Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread
comparing dates? Michael Joel <no@please.com> - 2011-10-02 09:00 -0400
Re: comparing dates? houghi <houghi@houghi.org.invalid> - 2011-10-02 15:43 +0200
Re: comparing dates? Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-02 09:58 -0400
Re: comparing dates? Doug Miller <doug_at_milmacdotcom@example.com> - 2011-10-02 12:36 -0400
Re: comparing dates? gordonb.wr5h4@burditt.org (Gordon Burditt) - 2011-10-02 23:54 -0500
Re: comparing dates? Doug Miller <doug_at_milmacdotcom@example.com> - 2011-10-03 11:50 -0400
Re: comparing dates? Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-03 14:59 -0400
Re: comparing dates? bobm3@worthless.info - 2011-10-03 20:31 -0400
Re: comparing dates? Michael Joel <no@please.com> - 2011-10-04 09:27 -0400
Re: comparing dates? The Natural Philosopher <tnp@invalid.invalid> - 2011-10-04 15:43 +0100
Re: comparing dates? "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2011-10-06 11:00 +0200
csiph-web