Solved

phpMyAdmin - Date

Posted on 2010-09-23
5
1,095 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

730 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