Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Converting a Uk date to a mysql date

Posted on 2007-04-03
4
Medium Priority
?
180 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
[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
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

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