473,568 Members | 2,905 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

convert string to date

83 New Member
How can I convert a string like '11-oct-2006' into a valid mysql date?

the date_format doesnot change the string in requried date format.

create table sample(name varchar(20),dat e varchar(16));
insert into sample values('java',' 11-oct-2006');

but at the time of select statement convert the string into date to change the date format like 11-10-2006.

so please help me to solve my problem. i am using the dos prompt not in php.

Thanks in advance
Oct 11 '06 #1
4 82917
ronverdonk
4,258 Recognized Expert Specialist
A valid MySQL date would be YYYY-MM-DD, so to convert your string into that use
Expand|Select|Wrap|Line Numbers
  1.  select str_to_date('10-oct-2006', "%d-%b-%Y");
In order to get a date formtted DD-MM-YYYY you use
Expand|Select|Wrap|Line Numbers
  1. select date_format(str_to_date('10-oct-2006', "%d-%b-%Y"), "%d-%m-%Y");
Anyway, it is all in the MySQL manual!

Ronald :cool:
Oct 11 '06 #2
sang
83 New Member
A valid MySQL date would be YYYY-MM-DD, so to convert your string into that use
Expand|Select|Wrap|Line Numbers
  1.  select str_to_date('10-oct-2006', "%d-%b-%Y");
In order to get a date formtted DD-MM-YYYY you use
Expand|Select|Wrap|Line Numbers
  1. select date_format(str_to_date('10-oct-2006', "%d-%b-%Y"), "%d-%m-%Y");
Anyway, it is all in the MySQL manual!

Ronald :cool:

Thankyou but this already done

i want to call the field at the date place.

select date_format(str _to_date('11-oct-2006', "%d-%b-%Y"), "%d-%m-%Y");
+-----------------------------------------------------------------+
| date_format(str _to_date('10-oct-2006', "%d-%b-%Y"), "%d-%m-%Y") |
+-----------------------------------------------------------------+
| 10-10-2006 |
+-----------------------------------------------------------------+

In mytable i insert the date at use_date.
create table sample(name varchar(20),use _date varchar(16));

insert into sample values('java',' 11-oct-2006');

select name,date_forma t(str_to_date(' use_date', "%d-%b-%Y"), "%d-%m-%Y") from sample;

but it gives the output like this
+------+--------------------------------------------------------------+
| name | date_format(str _to_date('use_d ate', "%d-%b-%Y"), "%d-%m-%Y") |
+------+--------------------------------------------------------------+
| java | |
+------+--------------------------------------------------------------+

how to overcome this pls help
Thanks
Sang
Oct 11 '06 #3
sang
83 New Member
Thankyou but this already done

i want to call the field at the date place.

select date_format(str _to_date('11-oct-2006', "%d-%b-%Y"), "%d-%m-%Y");
+-----------------------------------------------------------------+
| date_format(str _to_date('10-oct-2006', "%d-%b-%Y"), "%d-%m-%Y") |
+-----------------------------------------------------------------+
| 10-10-2006 |
+-----------------------------------------------------------------+

In mytable i insert the date at use_date.
create table sample(name varchar(20),use _date varchar(16));

insert into sample values('java',' 11-oct-2006');

select name,date_forma t(str_to_date(' use_date', "%d-%b-%Y"), "%d-%m-%Y") from sample;

but it gives the output like this
+------+--------------------------------------------------------------+
| name | date_format(str _to_date('use_d ate', "%d-%b-%Y"), "%d-%m-%Y") |
+------+--------------------------------------------------------------+
| java | |
+------+--------------------------------------------------------------+

how to overcome this pls help
Thanks
Sang
This is also done by using

select name,date_forma t(str_to_date(u se_date, "%d-%b-%Y"), "%d-%m-%Y") from sample;

Thanks
Sang
Oct 11 '06 #4
ronverdonk
4,258 Recognized Expert Specialist
When you want an easier heading display for the date you could also format it like
Expand|Select|Wrap|Line Numbers
  1. select name,
  2. date_format(str_to_date(use_date, "%d-%b-%Y"), "%d-%m-%Y") 
  3. as My_Date 
Thus you would get a display like
Expand|Select|Wrap|Line Numbers
  1. +-------------+-------------+
  2. | name        | MyDate      |
  3. +-------------+-------------+
  4. | MyName      | 25-10-2006  |
  5. +-------------+-------------+
Ronald :cool:
Oct 11 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

13
9276
by: perplexed | last post by:
How do you convert a user inputted date to a unix timestamp before insterting it into your database? I have a form, with a textfield for a date that the user inputs in the format mm-dd-yyyy and three dropdow boxes for hours, minutes, and AM/PM. All of these need to be considered together and converted to one Unix Timestamp and then inserted...
2
39784
by: Hector A | last post by:
Hi I'm trying to convert a string that already looks like a date to a date that I can use when I pass it from java to the database. I receive the date in format yyyy-mm-dd and I need it to be a date variable in 'mm/dd/yyyy' or 'm/dd/yyyy' format. My code is shown below. Any suggestions? code: String sailYear =...
2
5073
by: Franck | last post by:
Hi, 'm gettin mad about date conversion. Here is the point. Got and add-in for Excel which call functions from a web service (on a remote server) The remote server has regional settings set to "en-UK" and date to
12
3832
by: DC Gringo | last post by:
How can I convert this pubLatest to a date with format "m/d/yyyy"? Dim pubLatest As New Date pubLatest = Me.SqlSelectCommand1.Parameters("@pubLatest").Value -- _____ DC G
1
4590
by: abcabcabc | last post by:
I write an application which can let user define own date format to input, How to convert the date string to date value with end-user defined date format? Example, User Defined Date Format as "dd/MM/yyyy" input as "01082003" convert to date value as, 01 Aug 2003 Example, User Defined Date Format as "yyyy,dd,MM"
4
39307
by: perryclisbee via AccessMonster.com | last post by:
I have dates of service for several people that range all over each month. ie: patient had dates of service of: 7/3/2006, 7/24/2006 and 7/25/2006. I need to create a new field via a query that will convert each of the records of these service dates to the first date of that month, with results showing: 7/1/2006, 7/1/2006, 7/1/2006. How would...
6
21186
by: vunet.us | last post by:
How can I convert UTC time such as 1173451235415 to a local time I can read? Thank you
8
6037
by: deepak_kamath_n | last post by:
Hello, I have the following scenario: 1. My application receives the date from another application as a string 2. The other application is running in a different time zone as compared to my app. 3. I need to convert the received date string in to a date w.r.t my local time zone.
4
30248
by: Ashraf Ansari | last post by:
Hi, How Can I convert MM/dd/yyyy format into dd/MM/yyyy and the date which is converted into dd/MM/yyyy should be in DateTime format. I do not want to store it as a string. Please help Thanks in advance
4
2986
by: =?Utf-8?B?YW5kcmV3?= | last post by:
I am running an ASP.net program written in VB. At one point I try to convert a date string into a date time object... this string is from a central dev server and the code works on many other machines. Convert.ToDateTime("") I get the string in the format MM/DD/YYYY (06/26/2007) The code breaks and I get the "String was not recognized...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7665
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6277
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5501
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.