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
 time in 24 hour format and current time

Author  Topic 

usafelix
Posting Yak Master

165 Posts

Posted - 2014-09-03 : 01:19:53
if now the system time is 2014-12-23 23:45:345 . then I want to calculate the sales amount with total and get current date and current hour filter by hh:00-hh:59 , my desire output is like below :

Current time:23:50 run this query
Date Time amount
2014-12-23 23:40 $10
2014-12-23 23:01 $5
2014-12-23 23:39 $5
Total :$20
Anyone can help write this query ?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-09-03 : 04:42:13
[code]
SELECT [date] = dateadd(day, datediff(day, 0, createdatetime), 0),
[time] = convert(varchar(5), createdatetime, 108),
[amount] = sum(actualsalesamt)
FROM xsodetail
WHERE createdatetime >= dateadd(hour, datediff(hour, 0, getdate()), 0),
AND createdatetime >= dateadd(hour, datediff(hour, 0, getdate()) + 1, 0)
GROUP BY dateadd(day, datediff(day, 0, createdatetime), 0),
convert(varchar(5), createdatetime, 108)
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -