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
 General SQL Server Forums
 New to SQL Server Programming
 converting date

Author  Topic 

Rayman
Starting Member

39 Posts

Posted - 2010-11-09 : 16:59:27
I read the earlier post to see if someone had address this topic.
I have a column with the following data:

birth_date
4/23/1945
8/20/1962
3/27/1962
2/11/1958
3/21/1951
11/18/1951
8/15/1983
2/22/1971
1/24/1931
11/14/1944
12/15/1949
10/15/1965
9/25/1967
I need to read this and produce the following information:

day_born/age
Monday / 41.7
Wednsday/ 58.2
Saturday/ 78.4
Tuesday / 51.3
Sunday / 57.6
Thursday/ 59.5
Monday / 64.1
Friday / 43.6
Tuesday / 64.6
I placed the forward slash in the represent the space between the data and column.
But I need to calculate the date and extract the day of the week and the years


Terry Lynn King

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-11-09 : 17:15:35
Search the forums and Internet for various age functions. There are many. To figure out day_born, use DATENAME function with birth_date.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Rayman
Starting Member

39 Posts

Posted - 2010-11-10 : 12:36:19
SELECT person_name, birth_city,
dayname(birth_date) as day_born,
truncate(datediff(current_date,birth_date)/ 365,1) as age,
operations
FROM `john`
ORDER by person_name

The query is hanging on the dayname function. Is there a better way to do this? I reviewed the Microsoft SQL server transact-SQL and utilities reference, Vol 2. I am just missing a simple syntax issue.
The error states dayname not a recognize function. I change to Day and get the same thing.

Terry Lynn King
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-11-10 : 12:38:54
This doesn't look like Microsoft SQL Server. What dbms are you using?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Rayman
Starting Member

39 Posts

Posted - 2010-11-10 : 13:00:01
Microsoft SQL 2005 on Windows 2003 server.

Terry Lynn King
Go to Top of Page

TimSman
Posting Yak Master

127 Posts

Posted - 2010-11-10 : 13:05:28
There is no DayName function. Unless you wrote it.

And why do you have TRUNCATE in there? I would get rid of that, too.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-11 : 04:58:30
TRUNCATE is an ORACLE function. Also there is no reason to use it on the numbers as datediff will return integers

Madhivanan

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

- Advertisement -