Mukurdhom
Replies to this thread:
More by Mukurdhom
What people are reading
Subscribers
Please log in to subscribe to Mukurdhom's postings.
:: Subscribe
|
SQL Server, Date difference HELP
|
[VIEWED 6846
TIMES]
|
SAVE! for ease of future access.
|
|
|
|
Mukurdhom
Please log in to subscribe to Mukurdhom's postings.
Posted on 12-14-10 4:17
PM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
| |
Hello Gurus
I am kind of stuck here calculating the datetime difference.
Here is the problem
Environment: SQL Server 2008
Given: ResponseDate = '2010-10-02 06:05:13.120" ShippedDate='2010-10-03 07:08:25.780
Calculate date Difference = (ShippedDate - ResponseDate) = 1 01:03:12:660 1 = number of days 01 = Hours 03 = Minutes 12=Seconds 660= Milliseconds
My Query
SELECT ResponseDate ,ShippedDate ,DATEDIFF(day, ShippedDate, ResponseDate) AS DateDifference
This query returns only number of days.  Any gurus here in Sajha. Please help me.
|
| |
|
|
|
|
prankster
Please log in to subscribe to prankster's postings.
Posted on 12-14-10 4:28
PM [Snapshot: 16]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
| |
The argument day is not right - datepart
-
Is the part of startdate and enddate that specifies the type of boundary crossed. The following table lists all valid datepart arguments. User-defined variable equivalents are not valid. datepart | Abbreviations | year | yy, yyyy | quarter | qq, q | month | mm, m | dayofyear | dy, y | day | dd, d | week | wk, ww | hour | hh | minute | mi, n | second | ss, s | millisecond | ms | microsecond | mcs | nanosecond | ns |
|
| |
|
|
BI-Polar
Please log in to subscribe to BI-Polar's postings.
Posted on 12-14-10 4:33
PM [Snapshot: 24]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
| |
select top 100 Shippeddate,Responsedate, CAST(DATEDIFF(DD,Shippeddate,Responsedate) AS VARCHAR)+' '+CAST(DATEDIFF(HH,Shippeddate,Responsedate) AS VARCHAR) +':'+CAST(DATEDIFF(MM,Shippeddate,Responsedate) AS VARCHAR)+':'+CAST(DATEDIFF(SS,Shippeddate,Responsedate) AS VARCHAR) +':'+CAST(DATEDIFF(MS,Shippeddate,Responsedate) AS VARCHAR) From YourTabel This might work......
|
| |
|
|
Mukurdhom
Please log in to subscribe to Mukurdhom's postings.
Posted on 12-14-10 4:43
PM [Snapshot: 23]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
| |
I am using this syntax DATEDIFF ( datepart , startdate , enddate ) DATEDIFF(day, ShippedDate, ResponseDate)
This returns the correct number of days.
If i use other arguments, say Hour 2 days = it's returning 48
I think this cannot be done with a single query. Either a Function() or Stored Procedure.
Have you come across this situation? Or anyone in sajha.
|
| |
|
|
Mukurdhom
Please log in to subscribe to Mukurdhom's postings.
Posted on 12-14-10 4:52
PM [Snapshot: 47]
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
| |
It worked !!!  @Bi-Polar Thank you very much  @Pransketer Thank you for your help.  Just need some tuning in formating.. I can do that.
Sajha has always been a great help.
Happy Tuesday !!
|
| |
Please Log in! to be able to reply! If you don't have a login, please register here.
YOU CAN ALSO
IN ORDER TO POST!
Within last 60 days
| Recommended Popular Threads |
Controvertial Threads |
| ए १ पनि पुगेनछ ? |
| Democrat wants to run election like in India. Chaos and Confusing to voters. |
| नोबेल शान्ति पुरस्कार र अशान्त राष्ट्रपतिको बालहठ |
| नेपाली वालमार्ट चोर |
| 200 denaturalization cases per month to the Department of Justice for the 2026 fiscal year. |
| Funny when Nepalis talk about Epstein and injustice |
| मानसिक सन्तुलन, एक कहालीलाग्दो घटना सिक्नुपर्ने कुराहरु |
| Breaking News: Ninth Circuit Rejects Government Bid to Undo Nepal TPS Order, Leaves Protections in Place |
| Why Oli must go for the UML to survive? |
| मिरो प्रेडिक्शन जन्मेर एमेरिकामा आखा खो ल न पायेका नागरिकता बारे |
| नेपाली ससुरोले वर्जीनियामाँ आफ़नो छोरी नाती र ज्वाईलाई खुकुरी प्रहार |
| Sukulgunda 2.0 / www.sukulgunda.com |
| Why Prachanda seems to be the smartest of them all? |
| When will Nepali women be equal? |
| बालेंन मेयर बाट प्रधान मन्त्रि हुने भो ? |
| When will the culture of impunity end? |
| बालेंन आए पछि आशाका किरण देखिन थालेका छन् !! |
| Can we really get rid of Nepotism in the government? |
| आरको नेपालीले बेजत गर्यो फेरी अरविंग टेक्सासमा बुढ़ाहरू लाई स्कॉम गरेर |
| How many ministries do we really need? |
|
|
NOTE: The opinions
here represent the opinions of the individual posters, and not of Sajha.com.
It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address
if you want any posting to be considered for deletion. Your request will be
handled on a one to one basis. Sajha.com is a service please don't abuse it.
- Thanks.
|