Solved

Converting a Uk date to a mysql date

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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.

706 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

17 Experts available now in Live!

Get 1:1 Help Now