Solved

Converting a Uk date to a mysql date

Posted on 2007-04-03
4
174 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 142

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Integrate Office 365 calendar events into WordPress sites 2 52
How can i modify my File download link ? 6 47
What is the best PDF generator to use? 1 27
Session timeout 5 13
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
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.

911 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