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
 Need to add date time end of file

Author  Topic 

kalyan.cse05
Yak Posting Veteran

74 Posts

Posted - 2012-05-14 : 07:22:19
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
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-05-14 : 07:44:14
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

22864 Posts

Posted - 2012-05-14 : 09:37:15
or

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

Madhivanan

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

kalyan.cse05
Yak Posting Veteran

74 Posts

Posted - 2012-05-15 : 03:03:52
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
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-05-15 : 06:51:27
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

22864 Posts

Posted - 2012-05-16 : 04:23:35
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
   

- Advertisement -