SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need to add date time end of file
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kalyan.cse05
Yak Posting Veteran

India
68 Posts

Posted - 05/14/2012 :  07:22:19  Show Profile  Reply with Quote
i need to create a output text file and the suffix of that file will be datetime(yyyymmdd hhmmss). And in my table there is a column suffix.so what should i put in that field .
For example: if I put yyyymmdd in that field my out file file has been created with that sufix (e.g test20120514) but not able to put the time at the end of file name

kalyan Ashis Dey

sunitabeck
Flowing Fount of Yak Knowledge

5152 Posts

Posted - 05/14/2012 :  07:44:14  Show Profile  Reply with Quote
Perhaps you should put time also in to the data/query used to populate that column. You can do that like this:
SELECT REPLACE(REPLACE(CONVERT (VARCHAR(32),GETDATE(),120),'-',''),':','')
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22469 Posts

Posted - 05/14/2012 :  09:37:15  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
or

select convert(char(8),getdate(),112)+convert(char(10),getdate(),108)

Madhivanan

Failing to plan is Planning to fail

Edited by - madhivanan on 05/14/2012 09:39:31
Go to Top of Page

kalyan.cse05
Yak Posting Veteran

India
68 Posts

Posted - 05/15/2012 :  03:03:52  Show Profile  Reply with Quote
I think you did not get my query.
However let me explain the same again.
I need to create a text file and for that need to make some entries in the fields of a table and based on the entries of the field the text file will be created.
Now I have a field in the table named "Suffix". If i enter "yyyymmdd" in the field "Sufix" then my text file has been created with name "test20120515". I am able to do that. But i need the time as suffix of that file also.[for example: "test20120515035218"]. So my query is what should i enter in the field "Sufix" so that timestamp has also been added as a suffix of the text file. for you information I have tried with "yyyymmdd hhmmss". But no success. :(.

Thanks in advance for your help.

kalyan Ashis Dey
Go to Top of Page

sunitabeck
Flowing Fount of Yak Knowledge

5152 Posts

Posted - 05/15/2012 :  06:51:27  Show Profile  Reply with Quote
quote:
Originally posted by kalyan.cse05

I think you did not get my query.
However let me explain the same again.
I need to create a text file and for that need to make some entries in the fields of a table and based on the entries of the field the text file will be created.
Now I have a field in the table named "Suffix". If i enter "yyyymmdd" in the field "Sufix" then my text file has been created with name "test20120515". I am able to do that. But i need the time as suffix of that file also.[for example: "test20120515035218"]. So my query is what should i enter in the field "Sufix" so that timestamp has also been added as a suffix of the text file. for you information I have tried with "yyyymmdd hhmmss". But no success. :(.

Thanks in advance for your help.

kalyan Ashis Dey

I am afraid I am still not following what you are asking. Is the space between the date part and the time part the issue? If that is the case, modify the query like this:
REPLACE(REPLACE(REPLACE(CONVERT (VARCHAR(32),GETDATE(),120),'-',''),':',''),' ','')
That, of course, takes the current time and formats it in the way you described. If it is some other timestamp that you need to convert, you would replace the GETDATE() with whatever timestamp you wish to use. For example:
DECLARE @myTime DATETIME;
SET @myTime = '2012-04-11 16:23:57.090'

SELECT REPLACE(REPLACE(REPLACE(CONVERT (VARCHAR(32),@myTime,120),'-',''),':',''),' ','');
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22469 Posts

Posted - 05/16/2012 :  04:23:35  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
I hope you want to have something like this
http://beyondrelational.com/modules/2/blogs/70/posts/10795/backup-database.aspx

Change the style 112 to 120 and do replace - by '' as shown by Sunita

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000