Re: date formatting



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.

.



Relevant Pages

  • Re: Converting DD MM YYYY into YYYY-MM-DD?
    ... date representation format defined by ISO 8601. ... you should generate the map based on the standard library (in ... the underlying C standard library) locale database ... Doesn't the database have a timestamp data type? ...
    (comp.lang.python)
  • Re: [PhP - dB] About Formatting a Date Result
    ... In the MySQL database the field is set to date not timestamp as you ... foresight has stored a string date instead of a timestamp, ... and can format your date to that used, in the config files, for any user ...
    (php.general)
  • Re: Importing a timestamp
    ... Try importing it as text, then write an Update query to remove everything ... field to the table and write another Update query to populate the Date/Time ... I have set the advanced to be the correct date format. ... > can not get the timestamp to import. ...
    (microsoft.public.access.gettingstarted)
  • Re: [PHP] checking user input of MM-DD-YYYY
    ... Because I'm inserting it into MySQL as a date conversion from American ... All the more reason I would turn it into a timestamp or DateTime ... If you enter it in that format MySQL will get it right without regard ...
    (php.general)
  • RE: timestamp datatype
    ... You must tell Oracle what format your DATE or TIMESTAMP data is in, ... rather than the raw Oracle DATE or TIMESTAMP format. ...
    (perl.dbi.users)