|
-
Nov 12th, 2009, 09:12 AM
#1
Thread Starter
Fanatic Member
Problem with Datepart
Good Day all
i have the Following Query
Code:
DECLARE @CurrentTime DATETIME
SET @CurrentTime = CURRENT_TIMESTAMP
select tr.Descr [Room], tb.Purpose [Purpose], tb.Description [Description],
convert(varchar,datepart(hour,tb.starttime))+':'+convert(varchar,datepart(minute,tb.starttime)) [Start Time],
convert(varchar,datepart(hour,tb.endtime))+':'+convert(varchar,datepart(minute,tb.endtime)) [End Time],
tu.name [Requested by] from tbl_booking tb inner join tbl_resource tr
on tb.resources = tr.id
inner join tbl_user tu on tu.id = tb.RequestedByUser
where (day(startdate) = day(@CurrentTime))and(month(startdate)=month(@CurrentTime))and(year(startdate)=year(@CurrentTime))and(tb.status=1)
order by [Room],[Start Time]
and in the [Start Time]and [End Time] it gives me time that is not Complete
it Gives this
instead of
Thanks
-
Nov 12th, 2009, 09:39 AM
#2
Re: Problem with Datepart
You could pad the output with extra values.
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Nov 12th, 2009, 09:49 AM
#3
Re: Problem with Datepart
Here's an example with GetDate()
SQL Code:
--Tested On Microsoft SQL Server 2000 - 8.00.2040 select Left('0'+ convert(varchar,datepart(hour,getdate())),2)
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Nov 12th, 2009, 10:40 AM
#4
Re: Problem with Datepart
There is no need to use the DatePart function.
The Convert function can format the datetime fields into hh:mm.
Code:
select tr.Descr [Room], tb.Purpose [Purpose], tb.Description [Description],
convert(varchar(5), tb.starttime, 108) [Start Time],
convert(varchar(5), tb.endtime, 108) [End Time],
tu.name [Requested by]
from tbl_booking tb inner join tbl_resource tr
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|