473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

MySQL date format

I'm trying to insert a date into a MySQL date column. The string i am
trying to insert takes the following format:

2007-02-23

which corresponds to the date format that MySQL uses which is YYYY-MM-
DD. When i insert this into the database through an INSERT query
however the date field uses the value 0000-00-00. Why might this be?

Thanks

James

Feb 23 '07 #1
1 2208
jimmy wrote:
I'm trying to insert a date into a MySQL date column. The string i am
trying to insert takes the following format:

2007-02-23

which corresponds to the date format that MySQL uses which is YYYY-MM-
DD. When i insert this into the database through an INSERT query
however the date field uses the value 0000-00-00. Why might this be?

Thanks

James
When MySQL fails to parse a date value, it silently inserts a zero value
instead. (I just can not fathom the reasoning behind the choise to just
swallow an error without issuing an error message...)

The string that you are using has the ISO 8601 format, which is good, as
it's unambigous. I don't know why the database does not parse it
correctly, as it really should. You haven't forgotten to put apostrophes
around the value or something like that?

The solution is to use a parameterised query. Then the database driver
gets to worry about what date format to use. Turn the value into a
DateTime value before you put it into the parameter.

--
Göran Andersson
_____
http://www.guffa.com
Feb 23 '07 #2

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

Similar topics

4
by: Neil | last post by:
Hi, I hope this question isn't too far off topic....I'm almost at my wits end trying to figure this out. I have a Mysql database and I wish to automate the backup of the database because I...
1
by: Bruce | last post by:
I have an application where I would like to be able to allow the user to specify the date format used throughout the program (for internationalization). Then, on a date entry field, I can...
4
by: RT | last post by:
If anyone can help that would be great. Iım trying to format a timestamp from my MySQL table (sessions) Hereıs the code Iım using: <?php echo date('D,n-j-y h:i:s...
1
by: Neal | last post by:
I have a MySQL table with a datetime field that stamps the time the user submitted the form. It works and looks like this: $sql = "INSERT INTO table VALUES(....now())"; On another php page to...
2
by: Phil Nospam | last post by:
Hello all, I was browsing through the reference manual on the mysql.com web site and found the following code examples for some date/time functions: mysql> SELECT STR_TO_DATE('00/00/0000',...
2
by: Paul | last post by:
I am trying to insert a date into a mysql table but everytime I attempt it the date field is always empty. The field is of Date type and the date in code is in European format dd/mm/yyyy. ...
4
by: Dan Lewis | last post by:
I've imported a ms access database into a table in a mysql database. The access database contains a field that holds date/time values in 'general date' format. These all show up at 01/01/1970 in...
12
by: mantrid | last post by:
Hello Can anyone point me in the right direction for the way to read a text file a line at a time and separate the fields on that line and use them as data in an INSERT to add a record to a mysql...
1
by: paulq182 | last post by:
PLEASE HELP ME WITH MY CODE?? import java.sql.*; import java.io.*; class min_filmdb_rel_mysql { public static void main (String args ) throws SQLException, IOException {
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.