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 2005 Forums
 Transact-SQL (2005)
 separate nvarchar field

Author  Topic 

Exir
Posting Yak Master

151 Posts

Posted - 2009-05-05 : 03:45:24
I have a date field which is saved in varchar type in this format: dd/mm/yyyy
how can i separate and them into day,month and year?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-05-05 : 03:48:57
quote:
Originally posted by Exir

I have a date field which is saved in varchar type in this format: dd/mm/yyyy
how can i separate and them into day,month and year?


1 Use proper DATETIME datatype to store dates so that it is easy to do all date related caculations
2 Convert it to proper date and use DATEPART function

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-05-05 : 03:50:25
substring('dd/mm/yyyy',1,2) -- day
substring('dd/mm/yyyy',4,2) -- month
substring('dd/mm/yyyy',7,4) -- year


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Exir
Posting Yak Master

151 Posts

Posted - 2009-05-05 : 04:01:36
I can not save it in datetime type becouse the date is not in english date and datetime type doesnt save the year less than a special value
Go to Top of Page

Exir
Posting Yak Master

151 Posts

Posted - 2009-05-05 : 04:05:39
thank you webfred it worked
Go to Top of Page
   

- Advertisement -