Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI
I have created a database in Mysql and i have a datetime field in one of my tables. In my C Sharp code i create a DateTime object and i try to save in my database field. The date and time saves in the database but it is incorrect. I had the problem where i was getting an error when i saved DateTime.Now.ToString() to my database, it said incorrect date/time format. The date seperator in Mysql was a "-" and C# used a "/", so i manipulated the string and replaced "/" with "-" and it seemed to worked. The problem i have is that Mysql records every time as AM even though a PM time is being saved in it. Does anyone know how to solve this? :confused:

Thanks in advance for you help!
Posted
Updated 25-Mar-10 2:39am
v2

Don;'t use a string, use a datetime. Then there's no room for parsing errors.
 
Share this answer
 
The correct answer was already given. There is no need to shout on these forums - you will get an answer when someone is good and ready to give you an answer and not before. Do not use a string as a date in your sql, use a date. Use Parameterized queries and you will not have this problem. If you don't know what parameterised queries are you should start with the basics. If there is a problem inserting dates then convert to date in your sql SELECT Name FROM Table WHERE SalesDate = DATE(@SALESDATE) This works in MySql, maybe not in SQL server or Access.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900