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.
| 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 namekalyan 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),'-',''),':','') |
 |
|
|
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)MadhivananFailing to plan is Planning to fail |
 |
|
|
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 |
 |
|
|
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),'-',''),':',''),' ',''); |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|
|