SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQL server date formate


SQL server date formate

Author
Message
SQL Galaxy
SQL Galaxy
SSCertifiable
SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)

Group: General Forum Members
Points: 6725 Visits: 3501
select left(replace(replace(convert(varchar,getdate(),120),' ',' '),':',''),18)+'.txt'

The above script result is 2008-10-13 120155.txt

I want result like - 200810131201.txt

canu you tell how to eliminate the last two character.

Thanks
Kishore.P
Kishore.P
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2627 Visits: 619
Try the following way:

select replace (replace (left (replace (replace (convert (varchar, getdate(), 120), '', ''), ':', ''), 16), '-', ''), ' ', '') + '.txt'

Smile



SQL Galaxy
SQL Galaxy
SSCertifiable
SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)

Group: General Forum Members
Points: 6725 Visits: 3501
hi kishore, thanx for reply

It was working fine, but i need to be remove the sec in date.

as per query result is 20081013122619.txt

I want display only 200810131226.txt

thanks
Kishore.P
Kishore.P
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2627 Visits: 619
Ok, use left (..., 15) only. Copy the below code and try it again.

select replace (replace (left (replace (replace (convert (varchar, getdate(), 120), '', ''), ':', ''), 15), '-', ''), ' ', '') + '.txt'



SQL Galaxy
SQL Galaxy
SSCertifiable
SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)

Group: General Forum Members
Points: 6725 Visits: 3501
kishore, thank u very much for valuable reply
SQL Galaxy
SQL Galaxy
SSCertifiable
SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)

Group: General Forum Members
Points: 6725 Visits: 3501
Hi kishore, one more clarification, pls tell me

alter proc dateformatproc as
Declare @FileName varchar(255)
select @FileName = 'c:\Northwind Backup Plan4_' +
replace (replace (left (replace (replace (convert (varchar, getdate(), 120), '', ''), ':', ''), 15), '-', ''), ' ', '') + '.txt'
--select @FileName

the above script i had create procedure, This procedure return values like c:\Northwind Backup Plan4_200810151415.txt,
so how to call that procedure at place @messagefile location below

declare @rc int
exec @rc = master.dbo.xp_smtp_sendmail
@FROM = N'WJMN0130136',
@FROM_NAME = N'JG-IDC-SQL Server',
@TO = N'ananda.murugesan@zmail.ril.com',
@replyto = N'',
@CC = N'',
@BCC = N'',
@priority = N'NORMAL',
@subject = N'Hello IDC SQL Server Mail @ jamnager',
@message = N'Goodbye have a nice day, this is for test mail from MSSQL',
@messagefile = N'',
@type = N'text/plain',
@attachment = N'',
@attachments = N'',
@codepage = 0,
@server = N'10.4.54.22'
select RC = @rc
go
GilaMonster
GilaMonster
SSC Guru
SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)

Group: General Forum Members
Points: 221576 Visits: 46281
Aslo asked here:
http://www.sqlservercentral.com/Forums/FindPost584664.aspx

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search