Crystal Reports & SQL Reporting Services Training Consultants
Account Log in:
Username:
Password:
Be encouraged by your successes
 
Institute of IT Trainers - Freelance Trainer of the Year 2006 & 2009
Liverpool Business Connect Member
  Maximum Impact Solutions Limited - Reporting Solutions, Creating Answers
Reporting Solutions - Creating Answers, Crystal Reports, Dashboarding (Xcelsius) & SQL Reporting Services

The Maximum Impact Solutions Blog Feed ME!!!!

12
February

How Do I Split the Date and Time from a DateTime field using SQL

During a recent SQL Server Reporting Services report writing project the client needed to separate the Date and Time from a DateTime field



Solution:


To split a date time field into its component date and time values, I have used the Convert function, but the Cast function can also be used.

For the date field, the SQL was formatted for the UK date format:

SELECT [Tablename.DateTimeField],
CONVERT(Varchar(10),CONVERT(Date,[Tablename.DateTimeField]),103) as [Shipped Date],
CONVERT(Varchar(8),CONVERT(Time,[Tablename.DateTimeField])) as [Shipped Time]
FROM Tablename


If you have any questions, leave us a comment below, or need any assistance, please do not hesitate to Contact Us

MAKE A COMMENT

Name *

Email Address *

Comment *