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
 General SQL Server Forums
 New to SQL Server Programming
 How to get the difference of a datetime

Author  Topic 

ryoka012
Starting Member

20 Posts

Posted - 2012-09-03 : 22:45:09
Hi Guys,

Could anyone help me with the datetime computation.
Here is the scenario

i have declared a @mydate as dateime
and i have default value of a Column Startdate of 9/3/2012 12:00:00 AM.
i tried to use computation @mydate - Startdate.
and i have a value of '1900-01-02 10:42:29.890'.

my question is how can i convert this value in to non confusing value.

Thanks a lot.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-03 : 23:34:33
what do you mean by non confusing value

also try to pass datevalues in non ambiguos format

9/3/2012 12:00:00 AM. can represent 3rd of September or 9th or March depending on locale settings so better to pass values in YYYYMMDD format

see
http://visakhm.blogspot.com/2011/12/why-iso-format-is-recommended-while.html

also whats the unit in which you're trying to represent the difference ie hours,minutes etc


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

ryoka012
Starting Member

20 Posts

Posted - 2012-09-03 : 23:47:38
Thanks for the reply Visakh16

What i mean is i will if i have a value of getdate=9/1/2012 12:00:00 AM and startdate=9/3/2012 12:00:00 AM
and get the difference value like getdate-startdate i will have a value of 1900-01-02 10:42:29.890 which is confusing.

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-09-04 : 09:11:04
What do you want to return as a date?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-05 : 21:26:49
quote:
Originally posted by ryoka012

Thanks for the reply Visakh16

What i mean is i will if i have a value of getdate=9/1/2012 12:00:00 AM and startdate=9/3/2012 12:00:00 AM
and get the difference value like getdate-startdate i will have a value of 1900-01-02 10:42:29.890 which is confusing.




hmm?
why should you return difference as date value?
why not return it as integer value (2 days)

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -