Last post Jan 27, 2011 04:40 AM by hemant.yadav
Jan 21, 2011 06:23 PM|bastrix|LINK
I have a MySQL database with a field of type DateTime. When I try to send a date to the DB with the following format:
It does not save the time, only the date and a "00:00:00" at the end. For instance
Any idea how I can format save also hours, minutes and seconds? Would it be best to use Timestamps?
Thanks for any help.
Jan 22, 2011 12:21 AM|eatingmashin|LINK
It would be best to use the timestamp from the DB so that all date/time are synchronized across the application. If a client's local computer is set to a different time or timezone, DateTime.Now.ToString() would give a different date/time from the database.
You should let MySQL take care of any timestamps within your application especially for date_created and date_modified types of columns :)
Jan 22, 2011 12:44 AM|Prince Srivastava|LINK
Just use the DateTime.Now.ToString()
When u requrired to show in page then use the query with convert(varchar(10),fieldname,101)
Jan 22, 2011 07:30 AM|bastrix|LINK
Thanks for your answers.
I actually need the time. The scenario is a Front End Flash game to a .NET Back end where an AJAX timer on the page will post back the current time every certain amount of seconds. This allows me to keep track of the users that are online in that moment
and display them in the flash game.
So I will try TimeStamp, or maybe I could just do wit the "Time" data type...
Jan 23, 2011 06:42 AM|bastrix|LINK
Anyway... Might seem like something simple... but I have found that when switching from one database engine to another, these little "date" differences can cause you a huge headache.
For anyone with the same problem:
I solved this by using TIMESTAMP in mySql and format your DateTime in .NET liket this before you insert in the database:
Jan 27, 2011 04:40 AM|hemant.yadav|LINK
MySql datetime format support is different as compare to SqlServer. Here in your code you are only passing date section into database that why you are not able to save time into database
try following section.
If you want save second as well than try following
i hope this will help you.