Re: date formatting
- From: ZeldorBlat <zeldorblat@xxxxxxxxx>
- Date: Thu, 30 Aug 2007 02:19:02 -0000
On Aug 29, 5:12 pm, mi...@xxxxxxxxxxxxxx ("Mike Ryan") wrote:
I would like to have my users input the date formate as mm-dd-yyyy mysql
wants the data to come down as yyyy-mm-dd.
The question I have is how do I convert from the mm-dd-yyyy to yyyy-mm-dd so
that I can write it out to the database?
Let them input it in any format they want, then use strtotime() to
turn it into a timestamp. This gives you built-in validation as well
-- strtotime() will return false if the date is invalid. Once you
have a timestamp you can use date() to format it however you like
before sending it to MySQL.
This is cool because it is very tolerant of various date formats. My
users love it -- for reports that take a date range they can put in a
"end date" of today, and then put a "start date" of "3 months ago" or
"last thursday" and it just figures it out for you automatically.
.
- References:
- date formatting
- From: "Mike Ryan"
- date formatting
- Prev by Date: Re: [PHP] Internet Explorer Caching
- Next by Date: Re: : PHP Question - any help is appreciated
- Previous by thread: Re: [PHP] date formatting
- Next by thread: Re: [PHP] date formatting
- Index(es):
Relevant Pages
|