Re: A "bad" Unix Timestamp?

This is a discussion on Re: A "bad" Unix Timestamp? within the PHP Language forums, part of the PHP Programming Forums category; On Wed, 20 Oct 2004, Warren Oates wrote: > it turns out (and rightly so) that you can't create ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-21-2004
Matt Raines
 
Posts: n/a
Default Re: A "bad" Unix Timestamp?

On Wed, 20 Oct 2004, Warren Oates wrote:

> it turns out (and rightly so) that you can't create a "bad" Unix
> timestamp.
>
> date ("F d Y",strtotime("2004-09-31"));
>
> will return October 01 2004 and fwiw, so will
>
> date ("F d Y",mktime(0,0,0,9,31,2004));


Rightly or wrongly, I personally have found this quite a useful "feature".
It means you can *always* calculate the last date in the current month:
mktime(0, 0, 0, date("m") + 1, 0, date("Y"))

or tomorrow:
mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"))

This latter is nicer than time() + 86400 because that doesn't always
seem to return exactly midnight.

So in your example, you could determine if the user has entered 31 in a
month with only 30 days with:

if (date("d", mktime(0,0,0,$m+1,0,$y)) < $d) {
// not that many days in the selected month
}

Of course this assumes a valid $m and $y.

--
Matt
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:07 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0