Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

phpMyAdmin - Date

Posted on 2010-09-23
5
Medium Priority
?
1,117 Views
Last Modified: 2013-12-12
I have set up a table in phpMyAdmin using the "Date" field. It is set up as default to show the date as the following:

2007-08-10 i.e. Year-Month-Days

Is there anyway to change it to:

Days-Month-Year

?
0
Comment
Question by:petewinter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:guitar7man
ID: 33744237
I don't believe so, it's a MySQL thing. But I could be wrong.

Why not just store the date as a timestamp (MySQL INT) and then using PHP just format the date as you see fit?
0
 

Author Comment

by:petewinter
ID: 33744302
Thanks for your reply.

My issue is that when users are adding the date into a form. It is added in the following format:

dd/mm/yy

but then MySQL changes it to:

yy/mm/dd

which creates an incorrect date. ie. mysql use the dd as the yy

How do I get around this problem?
0
 

Author Comment

by:petewinter
ID: 33744320
I know I could just set the type up as varchar, but this causes the sort by date to be incorrect?
0
 
LVL 3

Accepted Solution

by:
guitar7man earned 2000 total points
ID: 33744368
If it was me, I'd take the user-submitted date and convert it to a timestamp, then save the timestamp to the DB in an INT field (this allows sorting). Then in the PHP code, I'd parse the timestamp to be whatever date format I see fit.

http://us.php.net/manual/en/function.date.php

If this isn't an option, then you'd have to account for the MySQL format, and readjust the user submission. You could do this with explode pretty easily. Something like:

$pieces = explode('/', $date_submission);
$mysql_date = $pieces[2] . '/' . $pieces[1] . '/' . $pieces[0];

then you can insert the $mysql_date var into the database which matches yy/mm/dd
0
 

Author Closing Comment

by:petewinter
ID: 33744697
Many Thanks
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this article, we’ll look at how to deploy ProxySQL.
The viewer will learn how to dynamically set the form action using jQuery.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question