|
Home > Archive > MS SQL Server > October 2006 > string to date conversion query
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
string to date conversion query
|
|
| jjaggii 2006-10-24, 6:33 pm |
| Hi
I was given this to convert a string to a date, where the date column
is a date of birth:
declare @dt varchar(20)
set @dt=3D'01012000'
select
convert(datetime,sub
string(@dt,5,4)+subs
tring(@dt,1,2)+subst
ring(@dt,3,2),1=
=AD12)
Now I have been trying to use this in a query to find the number of
records in a table between 2 dates of birth. I'm getting many syntax
errors in my attempts to write the query. Needless to say I'm not a
coder!! Can anyone help?
TIA
| |
| Andrew J. Kelly 2006-10-24, 6:33 pm |
| Have a look at these:
http://www.karaszi.com/SQLServer/info_datetime.asp
Guide to Datetimes
http://www.sqlservercentral.com/col...sqldatetime.asp
Datetimes
http://www.murach.com/books/sqls/article.htm
Datetime Searching
--
Andrew J. Kelly SQL MVP
"jjaggii" <richardwsmit@gmail.com> wrote in message
news:1159782053.220371.31660@c28g2000cwb.googlegroups.com...
Hi
I was given this to convert a string to a date, where the date column
is a date of birth:
declare @dt varchar(20)
set @dt='01012000'
select
convert(datetime,sub
string(@dt,5,4)+subs
tring(@dt,1,2)+subst
ring(@dt,3,2),1_12)
Now I have been trying to use this in a query to find the number of
records in a table between 2 dates of birth. I'm getting many syntax
errors in my attempts to write the query. Needless to say I'm not a
coder!! Can anyone help?
TIA
| |
|
|
| Hugo Kornelis 2006-10-24, 6:33 pm |
| On 2 Oct 2006 02:40:53 -0700, jjaggii wrote:
>Hi
>I was given this to convert a string to a date, where the date column
>is a date of birth:
>declare @dt varchar(20)
>set @dt='01012000'
>select
> convert(datetime,sub
string(@dt,5,4)+subs
tring(@dt,1,2)+subst
ring(@dt,3,2),1_12)[
/color]
Hi jjaggii,
The last parameter should be 112, not 1-12. With that change, the code
works.
[color=darkred]
>Now I have been trying to use this in a query to find the number of
>records in a table between 2 dates of birth. I'm getting many syntax
>errors in my attempts to write the query. Needless to say I'm not a
>coder!! Can anyone help?
If you have more errors in your query, post the actual code you're
working with - preferably allongside wiith CREATE TABLE and INSERT
statements to create a test environment. See www.aspfaq.com/5006.
--
Hugo Kornelis, SQL Server MVP
|
|
|
|
|