dbTalk Databases Forums  

Insert Date as Formatted String

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Insert Date as Formatted String in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
paulmac106@gmail.com
 
Posts: n/a

Default Insert Date as Formatted String - 02-22-2007 , 08:22 AM






Hello,

I thought this would be easy, and I've read a lot of posts, but I
can't seem to find exactly what I'm trying to do.

Quote:
From within a stored procedure I would like to insert a date value
into another table to a Char(8) field....but I want the value to be
formatted as YYYYMMDD (specifically no "/"'s)

Insert into Temp (sFromDate) Values (getdate()) (20070221)

Any ideas?

thanks so much!



Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Insert Date as Formatted String - 02-22-2007 , 08:30 AM






(paulmac106 (AT) gmail (DOT) com) writes:
Quote:
I thought this would be easy, and I've read a lot of posts, but I
can't seem to find exactly what I'm trying to do.

From within a stored procedure I would like to insert a date value
into another table to a Char(8) field....but I want the value to be
formatted as YYYYMMDD (specifically no "/"'s)

Insert into Temp (sFromDate) Values (getdate()) (20070221)

convert(char(8), getdate(), 112)

Read more about Convert under the topic CAST and CONVERT in Books Online.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #3  
Old   
paulmac106@gmail.com
 
Posts: n/a

Default Re: Insert Date as Formatted String - 02-22-2007 , 08:53 AM



On Feb 22, 9:30 am, Erland Sommarskog <esq... (AT) sommarskog (DOT) se> wrote:
Quote:
(paulmac... (AT) gmail (DOT) com) writes:
I thought this would be easy, and I've read a lot of posts, but I
can't seem to find exactly what I'm trying to do.

From within a stored procedure I would like to insert a date value
into another table to a Char(8) field....but I want the value to be
formatted as YYYYMMDD (specifically no "/"'s)

Insert into Temp (sFromDate) Values (getdate()) (20070221)

convert(char(8), getdate(), 112)

Read more about Convert under the topic CAST and CONVERT in Books Online.

--
Erland Sommarskog, SQL Server MVP, esq... (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Perfect! Thank you!!



Reply With Quote
  #4  
Old   
Utahduck@hotmail.com
 
Posts: n/a

Default Re: Insert Date as Formatted String - 02-22-2007 , 09:17 AM



On Feb 22, 7:22 am, paulmac... (AT) gmail (DOT) com wrote:
Quote:
Hello,

I thought this would be easy, and I've read a lot of posts, but I
can't seem to find exactly what I'm trying to do.

From within a stored procedure I would like to insert a date value

into another table to a Char(8) field....but I want the value to be
formatted as YYYYMMDD (specifically no "/"'s)

Insert into Temp (sFromDate) Values (getdate()) (20070221)

Any ideas?

thanks so much!
FYI, here are all the date conversions I've been able to find (use as
CONVERT(varchar, GetDate(), #) ):

# Format8
0 Oct 7 2003 10:59AM
1 10/07/03
2 03.10.07
3 07/10/03
4 07.10.03
5 07-10-03
6 07 Oct 03
7 Oct 07, 03
8 10:59:00
9 Oct 7 2003 10:59:00:763AM
10 10-07-03
11 03/10/07
12 031007
13 07 Oct 2003 10:59:00:763
14 10:59:00:763
20 2003-10-07 10:59:00
21 2003-10-07 10:59:00.763
22 10/07/03 10:59:00 AM
23 2003-10-07
24 10:59:00
25 2003-10-07 10:59:00.763
100 Oct 7 2003 10:59AM
101 10/07/2003
102 2003.10.07
103 07/10/2003
104 07.10.2003
105 07-10-2003
106 07 Oct 2003
107 Oct 07, 2003
108 10:59:00
109 Oct 7 2003 10:59:00:763AM
110 10-07-2003
111 2003/10/07
112 20031007
113 07 Oct 2003 10:59:00:763
114 10:59:00:763
120 2003-10-07 10:59:00
121 2003-10-07 10:59:00.763
130 11 ????? 1424 10:59:00:763AM
131 11/08/1424 10:59:00:763AM



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.