Page 1 of 1

DATE and DATETIME types in mysql

Posted: Thu Jan 30, 2014 8:00 am
by boylesg
If you use these types when setting up a table in MySQL, what exactly do you retrieve that field in a php query?

Is it some sort of string or some sort of object that you interrogate?

Re: DATE and DATETIME types in mysql

Posted: Thu Jan 30, 2014 8:27 am
by Celauran
You get back a string, which you can then use to create a DateTime object or pass to strtotime if you're looking to manipulate the formatting.

Re: DATE and DATETIME types in mysql

Posted: Thu Jan 30, 2014 8:38 am
by boylesg
Celauran wrote:You get back a string, which you can then use to create a DateTime object or pass to strtotime if you're looking to manipulate the formatting.
A standard char x[] type string or something different? Because in MySQL there is also a vchar type that I am not really familiar with.

Also, when you do a save or update on the database, how do you apply a datetime to the database column? Can it be in any format you like, e.g. d/m/yyyy hh:mm:ss, or does it have to be specifically in yyyy/m/d hh:mm:ss format so that queries with date ranges work properly with ascii collation?

Re: DATE and DATETIME types in mysql

Posted: Thu Jan 30, 2014 8:58 am
by Celauran
You insert a string, you retrieve a string. Default format is YYYY-MM-DD HH:MM:SS. MySQL has functions that allow manipulation of format, but I generally stick to the default and manipulate formats in PHP.

Re: DATE and DATETIME types in mysql

Posted: Thu Jan 30, 2014 9:39 am
by boylesg
Celauran wrote:You insert a string, you retrieve a string. Default format is YYYY-MM-DD HH:MM:SS. MySQL has functions that allow manipulation of format, but I generally stick to the default and manipulate formats in PHP.
I might do the same then, thanks for all that.