473,765 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

loading date strings as dates

Now that MySQL 5.0.15 is production ready, are there any functions to
use with mysqlimport, so I can load a string such as, MM/dd/yy, in a
text file into a MySQL database as a yyyy-MM-dd date value.
Thanks,
Yasaswi

Oct 25 '05 #1
4 4857
I doubt that you can do this directly. I would import the date values into a
char field and use the substring function to build the date in the right
format that works with a date field.

Markus
Oct 25 '05 #2
Hi Markus:
What do you mean by import the date values into a char field? I have a
data comma separated text file. One column has date in MM/dd/yy format?
Using mysqlimport command, how would I do what you are suggesting?
May be I can run a perl or shell script on the file first, to re-format
all the data columns in yyyy-MM-dd format and then run the mysqlimport
command. Please comment.
Thanks,
Yasaswi
Markus Popp wrote:
I doubt that you can do this directly. I would import the date values into a
char field and use the substring function to build the date in the right
format that works with a date field.

Markus


Oct 26 '05 #3
yasaswi wrote:
Hi Markus:
What do you mean by import the date values into a char field? I have a
data comma separated text file. One column has date in MM/dd/yy format?
Using mysqlimport command, how would I do what you are suggesting?
Design the table into which you are importing the data so that the field
in the position matching your MM/dd/yy values is a CHAR(10) or similar.

After you import the data successfully, add a date column to the table
(using ALTER TABLE), and copy the values from the CHAR(10) field to the
date field, while parsing the values:

UPDATE myTable
SET dateField = STR_TO_DATE(cha rField, '%m/%d/%y');

Then drop the CHAR(10) field if you wish.

See docs on STR_TO_DATE() function here:
http://dev.mysql.com/doc/refman/5.0/...functions.html
May be I can run a perl or shell script on the file first, to re-format
all the data columns in yyyy-MM-dd format and then run the mysqlimport
command. Please comment.


I use the Date::Manip Perl module for date parsing and reformatting.
See http://search.cpan.org/~sbeck/DateManip-5.44/Manip.pod

Regards,
Bill K.
Oct 27 '05 #4
> Design the table into which you are importing the data so that the field
in the position matching your MM/dd/yy values is a CHAR(10) or similar.

After you import the data successfully, add a date column to the table
(using ALTER TABLE), and copy the values from the CHAR(10) field to the
date field, while parsing the values:

UPDATE myTable
SET dateField = STR_TO_DATE(cha rField, '%m/%d/%y');

Then drop the CHAR(10) field if you wish.


That's exactly what I meant ;-).

Markus
Oct 27 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
9445
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $ Last-Modified: $Date: 2003/10/28 19:48:44 $ Author: A.M. Kuchling <amk@amk.ca> Status: Draft Type: Standards Track
3
3737
by: praba kar | last post by:
Dear All, I have doubt regarding date string to time conversion function. In Python I cannot find flexible date string conversion function like php strtotime. I try to use following type function 1) parsedate function failed if a date string like below format "16-MAY-2005 01:26" 2)parsedate_tz function also failed if a date string
15
43016
by: Simon Brooke | last post by:
I'm investigating a bug a customer has reported in our database abstraction layer, and it's making me very unhappy. Brief summary: I have a database abstraction layer which is intended to mediate between webapps and arbitrary database backends using JDBC. I am very unwilling indeed to write special-case code for particular databases. Our code has worked satisfactorily with many databases, including many instances MS SQLServer 2000...
3
6130
by: seegoon | last post by:
Hi to all. I have a small problem I hope someone can help me with. I am running a sql query to a csv file. The query searches for the total of a column between 2 dates. This is a copy of one of the query's: Dim SF_SMT As New OleDb.OleDbCommand("Select count(*) from fault_records.csv where F4 = '" & lblprod.Text & " ' " & " AND F8 AND F1 between #" & SelectproductForm.datestart & "# and #" & Now.Date &
3
10229
by: Tiya | last post by:
Hi there !!! I would like to know how to compare dates in javascript. var sdate = new Date(theform.SubmissionDate.value); var odate = new Date(theform.StartDate.value); var todaysdate = new Date(); if(sdate < todaysdate)
8
2112
by: Charlie Brookhart | last post by:
I am creating a program that involves having to find the difference between two dates and converting it to a number to be used for calculations. The problem is that the way it is setup, VB is not doing anything with the dates that I have selected. I hope that someone here can help me figure out why it is not working what I have to do to make it work. This the code I have for the date calculations. txtNumberOfDays.text =...
44
10230
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
3
4279
by: abctech | last post by:
I have an Html page, user enters a Date (dd-mm-yyyy) here. There's a servlet connected in the backend for processing this submitted information, it must have a method to compare this entered date with the dates obtained from the backend table which again are retrieved as strings (dd-mm-yyyy). Can anyone suggest how to carry out comparision between these date strings? Eg: String Entered Date: "28-02-2007" String Backend Date:...
6
1563
by: vdicarlo | last post by:
I am a programming amateur and a Python newbie who needs to convert about 100,000,000 strings of the form "1999-12-30" into ordinal dates for sorting, comparison, and calculations. Though my script does a ton of heavy calculational lifting (for which numpy and psyco are a blessing) besides converting dates, it still seems to like to linger in the datetime and time libraries. (Maybe there's a hot module in there with a cute little function...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9399
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7379
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5276
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3924
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
3
2806
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.