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
Solved

Convert Mysql varchar (10) dd/mm/yyyy to varchar (10)  YYYY-MM-DD format

Posted on 2012-04-10
2
391 Views
Last Modified: 2012-04-11
Our database contains a table called accountinfo with a column called fields_4 the current format is this:
3/15/2012      
3/16/2012      
3/17/2012      
3/18/2012      

This is what we would like to have.
2012-03-15      
2012-03-16      
2012-03-17      
2012-03-18      
We need to keep the format in varchar for scripting reasons not date format.

I was thinking something like this
Set Date_Field = Convert(datetime, VarChar_Field, 101) .
Thanks
0
Comment
Question by:CityInfoSys
2 Comments
 
LVL 24

Accepted Solution

by:
johanntagle earned 500 total points
ID: 37830814
set Date_Field = str_to_date(VarChar_Field,'%m/%d/%Y')

While the output for str_to_date is of date datatype, it can be stored to a varchar field.  See below:

mysql> create table test_date(v varchar(10), d varchar(10));
Query OK, 0 rows affected (0.07 sec)

mysql> insert into test_date (v) values ('3/15/2012'),('3/16/2012'), ('3/17/2012'), ('3/18/2012');
Query OK, 4 rows affected (0.00 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> update test_date set d=str_to_date(v,'%m/%d/%Y');
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> select * from test_date;
+-----------+------------+
| v         | d          |
+-----------+------------+
| 3/15/2012 | 2012-03-15 |
| 3/16/2012 | 2012-03-16 |
| 3/17/2012 | 2012-03-17 |
| 3/18/2012 | 2012-03-18 |
+-----------+------------+
4 rows in set (0.00 sec)

Open in new window

0
 
LVL 1

Author Closing Comment

by:CityInfoSys
ID: 37832846
Thanks for taking the time to show the example.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
showing numeric numbers 2 38
Create a Select Query and Populate a Table 3 51
Display images from mysql blob type (Not working) 9 41
Currency in SQL? 2 30
All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 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