Solved

Converting a Uk date to a mysql date

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

860 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