[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1032
  • Last Modified:

SQL 2005 SELECT statement - simple datetime issue

This is a really simple syntax issue. I have the following select statement:

SELECT dbo.CONTENT_Event.eventID, dbo.CONTENT_Event.EventName + ' (' + EventOrgName + ')' + EventDate

which returns the following error:

Conversion failed when converting datetime from character string.

All I want to know is the correct syntax for returning the date only from the EventDate datetime field in dd/mm/yyyy format. By the way, I'm restricted to returning 2 columns of data, hence the select statement format.

Thanks for any help.
0
asrisbey
Asked:
asrisbey
1 Solution
 
Ashish PatelCommented:
Try this.

SELECT dbo.CONTENT_Event.eventID, dbo.CONTENT_Event.EventName + ' (' + EventOrgName + ')' + Cast(EventDate as varchar)
0
 
HuyBDCommented:
try this
SELECT dbo.CONTENT_Event.eventID, dbo.CONTENT_Event.EventName + 
' (' + EventOrgName + ')' + convert(varchar,EventDate,103)

Open in new window

0
 
Ashish PatelCommented:
and for dd/mm/yyyy

SELECT dbo.CONTENT_Event.eventID, dbo.CONTENT_Event.EventName + ' (' + EventOrgName + ')' + Convert(varchar(10), EventDate, 103)
0
 
f_o_o_k_yCommented:
You should use convert

example:

SELECT dbo.CONTENT_Event.eventID, dbo.CONTENT_Event.EventName + ' (' + EventOrgName + ')' + Convert(varchar(10), EventDate, 103)
0
 
asrisbeyAuthor Commented:
I knew it would be easy! Thanks, works a treat.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now