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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 date

Author  Topic 

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2004-08-25 : 10:58:56
assuming you have a varchar field which is holding a date, i.e. 2005219
Notice thatthe first four letters indicate the year and the last 3 indicate the day of the year.
Using this how can I convert this into a datetime field value?
Thanks

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2004-08-25 : 11:01:07
Fouond the answer.
Thanks
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-08-25 : 11:03:43
heres a problem...

it could be
2005|2|19 => 2/19/2005
or
2005|21|9 => 9/21/2005


Something to think about.


Corey
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2004-08-25 : 11:04:30
or 219...being a Julian date
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-25 : 11:07:20
fmardani: post the answer

he probably meant that 219 was the 219th day of the year.

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-08-25 : 11:11:32
He did mean it was the day of the year.
It's exactly what he posted.

quote:
the last 3 indicate the day of the year.


Duane.
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-08-25 : 11:16:13
ahhh... my bad then!

Corey
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-25 : 11:21:33
well any ways this should work:
here the first day of the year is marked as 0 so its zero based. 1.1. = day 0
select substring('2005219', 1,4) as year,
datepart(mm, cast(substring('2005219', 5,3) as int)) as month,
datepart(dd, cast(substring('2005219', 5,3) as int)) as day

i just wonder if he did the same.


Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-08-25 : 11:29:09
He wanted it in one datetime field - so I'm guessing he did something like this:

select cast(substring('2005219', 1,4) + '-' + CAST(datepart(mm, cast(substring('2005219', 5,3) as int)) as VARCHAR(2)) + '-' + CAST(datepart(dd, cast(substring('2005219', 5,3) as int)) as VARCHAR(2)) as DATETIME) as MyDateTimeField

...........But we will never know if he doesn't post it.


Duane.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-25 : 11:31:56
altough i'm wondering why would someone have dates stored like this?? i mean where are the benefits???

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page
   

- Advertisement -