Jump to content
Barny74

Myphpadmin - DD MM YYYY ?

Recommended Posts

 

Anyone know how to get my database to recognise the date as DDMMYYYY , cant upload date as DDMMYYYY as it wants everything as YYYYMMDD.

Share this post


Link to post
Share on other sites

You don't. MySQL wants YYYYMMDD format, with optional separators, and either a 2- or 4-digit year.

 

Why can't you use that format?

Share this post


Link to post
Share on other sites

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') );

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thanks Thara. I have it in the DB as YYYYMMDD , currently i echo it as

 

echo $row ['date'];

 

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

 

Thanks

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Thanks , i just get a bit confused if i am running sql query or pho code. Thanks and will give it a go

Share this post


Link to post
Share on other sites

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.