Click here to Skip to main content
11,584,612 members (63,002 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: 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 0: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!
Smile | :)

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

  Print Answers RSS
0 OriginalGriff 430
1 Sergey Alexandrovich Kryukov 367
2 Dave Kreskowiak 260
3 Richard Deeming 220
4 virusstorm 194
0 OriginalGriff 1,703
1 Sergey Alexandrovich Kryukov 1,267
2 Abhinav S 711
3 Dave Kreskowiak 687
4 Suvendu Shekhar Giri 568

Advertise | Privacy | Mobile
Web04 | 2.8.150707.1 | Last Updated 21 Dec 2012
Copyright © CodeProject, 1999-2015
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