DATE and DATETIME types in mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
boylesg
Forum Newbie
Posts: 7
Joined: Mon Jan 27, 2014 5:09 am

DATE and DATETIME types in mysql

Post 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?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: DATE and DATETIME types in mysql

Post 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.
boylesg
Forum Newbie
Posts: 7
Joined: Mon Jan 27, 2014 5:09 am

Re: DATE and DATETIME types in mysql

Post 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?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: DATE and DATETIME types in mysql

Post 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.
boylesg
Forum Newbie
Posts: 7
Joined: Mon Jan 27, 2014 5:09 am

Re: DATE and DATETIME types in mysql

Post 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.
Post Reply