Click here to Skip to main content
12,634,101 members (26,668 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET
I have defined a field in my database table to store time. The default length of the field is 8. I am storing time from TimeODay which is displaying 12:44:10 PM
which overloads the data. How can I store this data to my DateTime field?

Posted 21-Dec-12 1:56am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If your database field is DateTime, then it stores the data as a number of microseconds since a specific data, so a 12 hour time will not overload the field - it will need to be converted to a DateTime before it is stored.

If your field is varchar then you need to either store your time as 24 hour format (i.e. without the AM/PM indicator) or preferably make it a DateTime field instead.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

datetime is stored properly...
when you want to fetch & display just set format in select statement

for display time in hh:mm:ss tt format...
use this
convert(varchar,datepart(hh,getdate()) % 12) + ':' + convert(varchar,datepart(Mi,getdate())) +':' + 
convert(varchar,datepart(ss,getdate())) + ' ' +

Replace Getdate() with your columnname
Happy Coding!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 21 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100