Solved

Converting a Uk date to a mysql date

Posted on 2007-04-03
4
177 Views
Last Modified: 2008-03-06
I have my dates in this format

DD/MM/YY

I need to convert it to mysql DATE  YYYY-MM-DDformat and back again.

In the past I have done this manually but is there a built in function for PHP or MYSQL to do this?

R.
0
Comment
Question by:roscoeh23
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 18845697
in MySQL, you can use the str_to_date function for the update:
$sql = "UPDATE yourtable SET yourdatefield = str_to_date('$yourdatevalue', '%m/%d/%Y') WHERE ... ";

and for the query, it's the Date_format function:
$sql = SELECT date_format(yourdatefield, '%m/%d/%Y') FROM yourtable WHERE ... ";


http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html
0
 

Expert Comment

by:Sailo100
ID: 18847462
$mysql_date = date("Y-m-d", strtotime($uk_date));
$sql = "UPDATE yourtable SET yourdatefield = '$mysql_date' WHERE ... ";

$sql = SELECT yourdatefield FROM yourtable WHERE ... ";
$uk_date = date("y/m/d", strtotime($mysql_date));
0

Featured Post

Technology Partners: 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

Suggested Solutions

Creating and Managing Databases with phpMyAdmin in cPanel.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

713 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