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
 Set the time up to minutes

Author  Topic 

archana23
Yak Posting Veteran

89 Posts

Posted - 2014-10-28 : 11:26:01
Hi, I am using below query to get the today date and time(2 hrs more than actual time)

select dateadd(HOUR, 2, getdate()) as time_added

the result of above query is "2014-10-28 13:19:09.343" but I want time up hours like shown below

"2014-10-28 13:00"

Thanks

Archana

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-10-28 : 11:40:22
[code]select dateadd(hour, datediff(hour, 0, getdate()) + 2, 0)[/code]


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

Go to Top of Page

archana23
Yak Posting Veteran

89 Posts

Posted - 2014-10-29 : 10:23:14
thank you..it worked

Archana
Go to Top of Page

archana23
Yak Posting Veteran

89 Posts

Posted - 2014-10-29 : 19:06:02
Can I get the date as yyyymmdd format I mean my result should be like below

"20141028 13:00"

Thank you..

Archana
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-10-30 : 04:19:57
that is formatting issue. You should do this in your front end application




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

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-10-30 : 04:20:28
if you really wants to do it in sql server, check out CONVERT() function
http://msdn.microsoft.com/en-sg/library/ms187928.aspx


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

Go to Top of Page

archana23
Yak Posting Veteran

89 Posts

Posted - 2014-10-30 : 10:14:37
If I added like this

select dateadd(dd, datediff(dd, 0, CONVERT(VARCHAR(10), getdate(), 112)), 0)

I am not getting correct results

getting as "2014-10-30 00:00:00.000"

can you please help me on this?

Archana
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-10-30 : 23:58:13
[code]select replace(convert(varchar(16), dateadd(hour, datediff(hour, 0, getdate()) + 2, 0), 121), '-', '')[/code]


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

Go to Top of Page
   

- Advertisement -