Jump to content

Myphpadmin - DD MM YYYY ?


Barny74
Go to solution Solved by Barand,

Recommended Posts

The correct format for MySql dates is YYYY-MM-DD. The format you are trying to save is useless (cannot be compared, cannot be sorted and cannot be used directly with datetime functions)

 

Specify your date column as type DATE. Convert to the correct format either before you insert, or during insert with STR_TO_DATE() function.

 

Example

INSERT INTO mytable (mydate) VALUES  (str_to_date('20012017', '%d%m%Y') );
Link to comment
Share on other sites

It doesn't matter. You can retrieve dates in whatever format you want

 

Eg: 

SELECT DATE_FORMAT('2017-01-23', '%d/%m/%Y')

But, you must however save all dates using the YYYY-MM-DD format as that is the only format that mysql date fields can accept

(it is also the only format where you can sort into date order)..

Edited by thara
Link to comment
Share on other sites

  • Solution

This is the part that is confusing me. How do i echo it out as DDMMYY

 

 

 

You could try reading thara's post again and use the function he gave you.

 

edit - alternatively you can do it in PHP

$dtobj = new DateTime($row['date']);
echo $dtobj->format('d/m/Y');               //--> 23/01/2017, for example
Edited by Barand
  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.