Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Time problem

Author  Topic 

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2009-03-03 : 02:39:29
hello

I found that wrong time part (AM/PM) in db timestamp.

I pass Datetime.Now from C# (eg. 3/25/2009 3:33:04 PM )

but it's inserted in db like ( 3/25/2009 3:33:04 AM)

May i know what's wrong ?

Thanks

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-03-03 : 03:16:47
see this
select '3/25/2009 3:33:04 PM',convert(varchar,'3/25/2009 3:33:04 PM'),convert(datetime,'3/25/2009 3:33:04 PM')
Go to Top of Page

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2009-03-03 : 07:23:59
Hello

Thanks for ur reply but
I dont get what u mean.
What's the cause of that problem and how can i solve it

quote:
Originally posted by bklr

see this
select '3/25/2009 3:33:04 PM',convert(varchar,'3/25/2009 3:33:04 PM'),convert(datetime,'3/25/2009 3:33:04 PM')

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-03 : 07:29:20
It seems the datetime information is truncated when you post the value to the database.
You are not using DATETIME parameter, are you?

When you truncate datetime information before AM/PM part, but after seconds, you will get AM as default.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2009-03-03 : 07:41:40

Problem resolved!
It is because i format that datetime in front end before inserting.

Thanks .

quote:
Originally posted by Peso

It seems the datetime information is truncated when you post the value to the database.
You are not using DATETIME parameter, are you?

When you truncate datetime information before AM/PM part, but after seconds, you will get AM as default.



E 12°55'05.63"
N 56°04'39.26"


Go to Top of Page

ddramireddy
Yak Posting Veteran

81 Posts

Posted - 2009-03-03 : 07:45:51
I think currently your column datatype is varchar, Use datetime type instead of varchar for better usage of those dates. So change that column to datetime datatype and try to insert date into that datatype. then there will not be any problem of AM/PM. And also you will not have any problems with datetime manipulations.

We can't expect the problem. May be i think when passing to the DB only, some where data is changing
Go to Top of Page

ddramireddy
Yak Posting Veteran

81 Posts

Posted - 2009-03-03 : 07:45:52
I think currently your column datatype is varchar, Use datetime type instead of varchar for better usage of those dates. So change that column to datetime datatype and try to insert date into that datatype. then there will not be any problem of AM/PM. And also you will not have any problems with datetime manipulations.

We can't expect the problem. May be i think when passing to the DB only, some where data is changing
Go to Top of Page
   

- Advertisement -