
Syntax DATEFORMAT ( date, format) Parameter Values Technical Details Works in: From MySQL 4. There are also several predefined date constants that may be used instead, so for example DATERSS contains the format string 'D, d M Y H:i:s'.

you must use exactly same time/zone before converting date to timestamp otherwise, strtotime() will use default server timezone. Definition and Usage The DATEFORMAT () function formats a date as specified. object Procedural style only: A DateTime object returned by datecreate () format The format of the outputted date string. Please be careful about time/zone if you set it to save dates in database, as I got an issue when I compared dates from mysql that converted to timestamp using strtotime. Unless you are working with localized date strings, the easier choice is likely DateTime. Yet another alternative is to use the IntlDateFormatter API: $formatter = new IntlDateFormatter( Note that if you do not set the !, the time portion will be set to current time, which is different from the first four which will use midnight when you omit the time. If the above fails because you are using a unsupported format, you can use $date = DateTime::createFromFormat('!d-m-Y', '22-09-2008') The same with the procedural API: $date = date_create('') 22 I have a mySQL database with a timestamp field. With DateTime API: $dateTime = new DateTime('') Therefore I recommend to always specify date format. It can save awkward debugging in the future.

Regardless, it's always a good starting point to be strict when parsing strings into structured data. (Same as " GMT".) $d = DateTime::createFromFormat( Timestamp is a data type and function in Standard Structured Query Language (SQL) that lets us store and work with both date and time data values, usually without specified time zones. (Same as New York.) $d = DateTime::createFromFormat( Entering it is optional - if you don't do it, it will result in making PHP get timestamp automatically and display the current local time ( time () ). If you want to specify in which time zone, here EST. Syntax Rules Explained The syntax rules for entering a date are rather simple: date (format, timestamp) The timestamp part describes an integer Unix timestamp. If you don't care about timezone, or want to use the time zone your server uses: $d = DateTime::createFromFormat('d-m-Y H:i:s', '22-09-2008 00:00:00') ġ222093324 (This will differ depending on your server time zone.) Tip: Also look at the date () function, which formats a local date/time. timestamp The optional timestamp parameter is an int Unix timestamp that defaults to the current local time if timestamp is omitted or null.

Note: This function does not use locales (all output is in English). Note: date() will always generate 000000 as microseconds since it takes an int parameter, whereas DateTime::format() does support microseconds if DateTime was created with microseconds.
#SQL TIMESTAMP PHP DATE FORMAT WINDOWS#
This method works on both Windows and Unix and is time-zone aware, which is probably what you want if you work with dates. The dateformat () function returns a date formatted according to the specified format.
