Reputation: 325
With the help of you guys on here, I have the following SQL Query:
SELECT DataLog.TimestampUTC,MeterTags.Name,DataLog.Data
FROM DataLog
INNER JOIN MeterTags
ON DataLog.MeterTagId = MeterTags.MeterTagId
WHERE DataLog.TimeStampUTC between cast(getdate() - 1 as date) and cast(getdate() as date) and
DataLog.MeterTagId Between 416 AND 462;
This returns a column "TimestampUTC" with YYYY-MM-DD hh:mm:ss. I'd like to drop the time within this column and only display YYYY-MM-DD.
Any help you could give would be really appreciated.
Thanks in advance.
Upvotes: 2
Views: 28399
Reputation: 132
You should use :
CAST(DataLog.TimestampUTC as date)
The code looks like:
SELECT CAST(DataLog.TimestampUTC as date),MeterTags.Name,DataLog.Data
FROM DataLog
INNER JOIN MeterTags
ON DataLog.MeterTagId = MeterTags.MeterTagId
WHERE DataLog.TimeStampUTC between cast(getdate() - 1 as date) and cast(getdate() as date) and
DataLog.MeterTagId Between 416 AND 462;
Upvotes: 0
Reputation: 44326
SELECT convert(char(10), DataLog.TimestampUTC, 120) as TimestampUTC,
MeterTags.Name,DataLog.Data
FROM DataLog
INNER JOIN MeterTags
ON DataLog.MeterTagId = MeterTags.MeterTagId
WHERE DataLog.TimeStampUTC between cast(getdate() - 1 as date) and cast(getdate() as date) and
DataLog.MeterTagId Between 416 AND 462;
Upvotes: 2
Reputation: 687
In SQL Server you can convert to Date
select Convert(Date, Convert(datetime, '2013/01/01 12:53:45'))
results:
2013-01-01
Upvotes: 1