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)
 How to get Time as well.

Author  Topic 

SCHEMA
Posting Yak Master

192 Posts

Posted - 2009-08-09 : 08:54:43
Now I have Backup as DBNAME_20090808.bak. It is transaction log backup. How do i get time as well like:

DBNAME_200908081000.bak for 10 A.M backup and DBNAME_200908082300.bak for 11 P.M Backup.

Currently I am using Variable as
@V = Convert(varchar,getdate(),112)

SCHEMA
Posting Yak Master

192 Posts

Posted - 2009-08-09 : 09:03:03
Any help?
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-08-09 : 09:31:16
select
convert(varchar(4),year(getdate()))+
right('00'+convert(varchar(2),month(getdate())),2)+
right('00'+convert(varchar(2),day(getdate())),2)+
right('00'+convert(varchar(2),datepart(hh,getdate())),2)+
right('00'+convert(varchar(2),datepart(mi,getdate())),2)


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

SCHEMA
Posting Yak Master

192 Posts

Posted - 2009-08-09 : 09:33:39
Thanks Webfred.

Can't it be more simpler?
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-08-09 : 09:34:56
select Convert(varchar,getdate(),112)+
right('00'+convert(varchar(2),datepart(hh,getdate())),2)+
right('00'+convert(varchar(2),datepart(mi,getdate())),2)


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

SCHEMA
Posting Yak Master

192 Posts

Posted - 2009-08-09 : 09:37:13
Yep thanks. That is what I came up with actually after reviewing yours.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-08-09 : 09:38:10
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-08-10 : 03:02:30
or


select convert(varchar(10),getdate(),112)+replace(convert(varchar(10),getdate(),108),':','')


Madhivanan

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

- Advertisement -