PHP MyAdmin
Moderator: General Moderators
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
PHP MyAdmin
Hi,
I use PHP MyAdmin to administer my MySQL databases.
In some of my tables I have a date field and I have the data type set as DATE. When I insert a date value from a web page into one of these date fields, it does not display. A default mask is used i.e. 00/00/0000.
The date value I insert is formatted as: date("d/m/y")
I know its quite difficult to comment on because you dont know my setup but any general suggestions would be greatly appreciated.
Thanks.
I use PHP MyAdmin to administer my MySQL databases.
In some of my tables I have a date field and I have the data type set as DATE. When I insert a date value from a web page into one of these date fields, it does not display. A default mask is used i.e. 00/00/0000.
The date value I insert is formatted as: date("d/m/y")
I know its quite difficult to comment on because you dont know my setup but any general suggestions would be greatly appreciated.
Thanks.
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
mysql has to perform a type cast string->date. and it can only understand that much formats, You have to choose a valid format for the input.
Take a look at http://dev.mysql.com/doc/refman/5.1/en/datetime.html
There's a section starting with
Take a look at http://dev.mysql.com/doc/refman/5.1/en/datetime.html
There's a section starting with
You can specify DATETIME, DATE, and TIMESTAMP values using any of a common set of formats:
when you add the date to the database add like
When you out put the date from the database use:
The database stores date in the format Y-m-d. If you are storing time and date, then store as:
Read about time and date function here:
http://uk3.php.net/manual/en/function.date.php
Code: Select all
<?php
// todays date
$today = date("Y-m-d");
?>Code: Select all
<?php
// $date_field is the field name in the database
echo date("d M Y", strtotime($date_field));
?>Code: Select all
<?php
// todays date
// G is hour, i is minute, s is seconds
$today = date("Y-m-d G:i:s");
?>http://uk3.php.net/manual/en/function.date.php
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
A date filed in MySQL stores dates as YYYY-MM-DD by default. A DateTime field stores them as YYYY-MM-DD HH:MM:SS by default. When you insert dates into that database, it is best to insert them in the format that it is expecting otherwise it may have to guess. In which case it may guess wrong and you may get a 0000-00-00 date.