I'm have a dilemma...
I'd like to store dates in MySQL as YYYY-MM-DD, so that when I transfer dates from my access database, they will convert smoothly.
The problem is that I can't seem to find a way to display the date as MM-DD-YYYY, when I pull them from the MySQL database as YYYY-MM-DD.
I know that I could save each piece of the date into 2 or 3 text parts and switch the order that I print them. But, there's gotta be an easier way.
Is using a timestamp the only way that you can "work" with a date (not just use it as text)?
Let's say I have a date as:
$CurrentDate = date('Y-m-d'); // YYYY-MM-DD
How do I now take $CurrentDate and make it display in the MM-DD-YYYY format?
Which type of date field should I use?
Moderator: General Moderators
One of php's greatest attributes is dates. See http://us4.php.net/manual/en/function.date.php for more information.
Re: Which type of date field should I use?
I think you mean (missing argument):Swede78 wrote:Is using a timestamp the only way that you can "work" with a date (not just use it as text)?
Let's say I have a date as:
$CurrentDate = date('Y-m-d'); // YYYY-MM-DD
How do I now take $CurrentDate and make it display in the MM-DD-YYYY format?
Code: Select all
<?php
$CurrentDate = date('Y-m-d', $timestamp);
?>If you don't have a timestamp, mktime() can create one.
See the mysql manual for date functions such as DAYOF WEEK, MONTH and YEAR.
I often work with timestamps stored in mysql integer columns and mostly ignore all the mysql date stuff - OK as long as you don't need to go further back than 01/01/1970.
Last edited by McGruff on Thu Aug 11, 2005 7:26 am, edited 1 time in total.
you might also use the date_format function in mysql to query the date in a format you like, e.g.
SELECT date_format(myTimestampField, '%c %e %Y') FROM myTable
http://www.mysql.com/doc/en/Date_and_ti ... ml#IDX1305
SELECT date_format(myTimestampField, '%c %e %Y') FROM myTable
http://www.mysql.com/doc/en/Date_and_ti ... ml#IDX1305