Solved

phpMyAdmin - Date

Posted on 2010-09-23
5
1,057 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
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:guitar7man
Comment Utility
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
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
Many Thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now