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
 Concatenating DateName and DatePart columns

Author  Topic 

FRoggers
Starting Member

2 Posts

Posted - 2012-07-13 : 18:10:13
Hello,

SQL is new to me so I am a complete newbie.

I need to get an output of two columns. One column will have a specific time stamp (i.e. 2009-03-17 15:40:47.940), which I understand. It the second column I can't figure out. The second column needs to contain the same date, but in the format of: weekday, month, date and year. What would the query look like?

The end result needs to be (of course the time will vary, hence the x's):
LastUpdated LastUpdated_Date
2009-03-17 xx:xx:xx.xxx Tuesday, March 17, 2009

This is the query I must modify:
Select top 1 LastUpdated
,DATENAME(weekday,LastUpdated) as 'Weekday'
,DATENAME(month,LastUpdated) as 'Month'
,DATEPART(day,LastUpdated) as 'Day'
,DATEPART(year,LastUpdated) as 'Year'
from Content(nolock)
where DataVersionId = 40269
and (LastUpdated >= '2009-03-17' and LastUpdated < '2009-03-18')


This is a "homework" assignment. Any guidance would be helpful.

Thank you.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-07-13 : 21:44:16
[code]
select convert(varchar(30), getdate(), 121),
datename(weekday, getdate()) + ', '
+ datename(month, getdate()) + ' '
+ datename(day, getdate()) + ', '
+ datename(year, getdate())
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

FRoggers
Starting Member

2 Posts

Posted - 2012-07-16 : 10:54:20
quote:
Originally posted by khtan


select convert(varchar(30), getdate(), 121),
datename(weekday, getdate()) + ', '
+ datename(month, getdate()) + ' '
+ datename(day, getdate()) + ', '
+ datename(year, getdate())



KH
[spoiler]Time is always against us[/spoiler]





Thanks khtan, but I need the data to show up in only two columns not six. The columns need to have headings as well.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-07-16 : 11:01:58
copy khtan's solution and paste it into a query window, then hit F5 and you will see two columns in the result pane.


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

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-07-16 : 11:04:19
quote:
Originally posted by FRoggers

quote:
Originally posted by khtan


select convert(varchar(30), getdate(), 121),
datename(weekday, getdate()) + ', '
+ datename(month, getdate()) + ' '
+ datename(day, getdate()) + ', '
+ datename(year, getdate())



KH
[spoiler]Time is always against us[/spoiler]





Thanks khtan, but I need the data to show up in only two columns not six. The columns need to have headings as well.



FOR HEADERS:

select convert(varchar(30), getdate(), 121) as YOURHEADER,
datename(weekday, getdate()) + ', '
+ datename(month, getdate()) + ' '
+ datename(day, getdate()) + ', '
+ datename(year, getdate()) as YOURHEADER

--------------------------
Get rich or die trying
--------------------------
Go to Top of Page
   

- Advertisement -