Actually, that’s not true. MySQL has its own Date format, and uses it
internally for any field that is specified as a Date, Time, Year,
DateTime or Timestamp. These dates usually take the form of ISO date-
time strings:
YYYY-MM-DD HH:MM:SS
There are obviously variations on that theme, but that’s the usual
format.
Many PHP/MySQL applications use the Unix timestamp format, simply
because it makes the math of dates that much easier to manage, and
also because there are lots of goodies baked into PHP itself for
handling these timestamps. When setting up a new PHP/MySQL
application to do this, you would specify the date field in your
database not as a MySQL Date type, but rather as a signed integer of
sufficient length to carry the particular date range you need to manage.
This is also a good practice if you are not sure that you are going
to stay in MySQL, since a signed integer is a very portable column
type across different database engines.
But if you want to be able to take advantage of MySQL’s date handling
magick in your queries, say to be able to say WHERE start_date BETWEEN '2001-12-1' AND '2002-12-1'
, then you need to use one of
MySQL’s Date column types in your database, and then format the
output in your own fashion (unless you like ISO dates for some
reason) for display.
Walter
On Mar 22, 2008, at 4:28 AM, David Ledger wrote:
At 14:44 -0400 21/3/08, WebWorker wrote:
Lets hope we all get there
Thanks for that…
But does MYSQL automatically convert dates into this date stamp? Or
do you have to have a PHP program converting a date into a date
stamp before uploading to the database?
In common with most, if not all, software that handles dates, MySql
stores a date as a single number not as a string. It not only makes
date manipulation easier, it makes a lot of things you expect and
need possible. It also takes less space. When you access the date
data from outside, even with say myphpadmin (phpmyadmin?), it shows
it as a string for you, but it’s still saved as a number.
David
–
David Ledger - Freelance Unix Sysadmin in the UK.
HP-UX specialist of hpUG technical user group (www.hpug.org.uk)
email@hidden
www.ivdcs.co.uk
dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options
dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options