473,386 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Insert Date as Formatted String

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!

Feb 22 '07 #1
3 11771
(pa********@gmail.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, es****@sommarskog.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
Feb 22 '07 #2
On Feb 22, 9:30 am, Erland Sommarskog <esq...@sommarskog.sewrote:
(paulmac...@gmail.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...@sommarskog.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!!

Feb 22 '07 #3
On Feb 22, 7:22 am, paulmac...@gmail.com wrote:
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

Feb 22 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: CFW | last post by:
I use the following flawlessly to insert a single field: strSQL = "Insert into (Casket) Values " _ & "(" & conQuote & NewCasket & conQuote & ")" Set db = CurrentDb If MsgBox(NewCasket & " is...
3
by: Leszek | last post by:
Hello, I believe there must be somwhere in .NET a method to easily deal with the following situation: 1. A user enters a date (myDate) in a format dd/mm/yyyy 2. A method checks if the myDate is...
1
by: Lerp | last post by:
Hi all, What do I have to do in order to get my value from my textbox that is formatted like 'mm/dd/yyyy' into a datetime database field ? Currently getting an error: Syntax error converting...
2
by: Paul | last post by:
I am trying to insert a date into a mysql table but everytime I attempt it the date field is always empty. The field is of Date type and the date in code is in European format dd/mm/yyyy. ...
10
by: RoadRunner | last post by:
Hi, I have a employee vacation database that has a vacation table that has the employee name, pay week and date of vacation. I have another lookup table with pay week code and date range for the...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
10
by: =?Utf-8?B?TWlrZQ==?= | last post by:
I have a string variable containing a date formatted as YYYYMMDD For example - Dim x as string = "20070314" If I try to perform a type conversion as follows I get an error: Dim y as Date =...
5
by: xzzy | last post by:
I am writing an app that enables a user to reply to a newsgroup. The proper syntax for From: is "screen name" email@address.com and over all, it should look like: --
2
by: AlRojo | last post by:
First, apologies for all the code; I'm not sure what is most relevant to my problem. I am trying to use the code below to select Records from an Access table called and insert them into another...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.