Abandon Hours, Minutes Etc From Datetime Datatype

Dec 13, 2007



Dear all,

I need to ignore the hours minutes and seconds elements of a datetime field - I've got a way of doing this in my select statement but it seems to be this can't be the most efficient way!

CONVERT(datetime, CONVERT(nchar(10), db.tab.field, 101)) AS date_key


Is there a better way?

View 4 Replies


ADVERTISEMENT

How Can I Get The Sum Of Hours Stored In A Datetime Datatype

Feb 3, 2007

I need to get (In a select statement, for a stored procedure) the SUM of hours stored in a datetime column (column name TaskHours). For example; (1/1/1900 3:30:00 AM, 1/1/1900 5:15:00 AM, 1/1/1900 4:45:00 AM) (3:30 + 5:15 + 4:45) this should sum to 13.5 hours.
(not 12.90)
I appreciate your help!

View 3 Replies View Related

T-SQL (SS2K8) :: Display Row As 2 Days Ago / 1 Hours 34 Minutes Ago / 11 Minutes Ago

Apr 21, 2015

My table as data as follow,

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[table_Data]') AND type in (N'U'))
DROP TABLE [dbo].[table_Data]
GO
/****** Object: Table [dbo].[table_Data] Script Date: 04/21/2015 22:07:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[table_Data]') AND type in (N'U'))

[code].....

View 6 Replies View Related

Converting Decimal Hours To Hours And Minutes

May 13, 2008

I have a float variable that holds a decimal number of hours.

So 1.5 equals 1 hour 30 minutes.

I need to change this to the format 1:30

Any idea how to do this?

View 10 Replies View Related

Days Hours Minutes

Apr 18, 2008

I have two field and I need to find the sum I guess of them. One is called the clm_dout (process date) and the other one is clm_rcvd (received Date). These are both date and time fields and it looks like this 2006-03-17 00:00:00.000. I need to create a formula that wiil i guess give me the difference and create it into hour and minutes because I an trying to create a turn around report. this is what I had...

TimeValue({clm_doubt}-{clm_rcvd})

This is not working for me. Can someone give me a suggestion please.

Thanks!

View 2 Replies View Related

Calculate Hours And Minutes

Nov 6, 2006

Hi
Can anyone help me convert a number to give the result in hours and minutes? For example 195 as 3:15 or 210 as 3:30. We are trying to create a report showing hours and minutes worked without having to export to Excel.

I've had a look around the net and this seems to be quite a difficult function in SQL Server.

Any guidance much appreciated.

View 7 Replies View Related

Hours And Minutes Question

Jun 19, 2007

Hi guys,

how to get the Hours and Minutes ago?

I have a column name "DateCreated" which is a DateTime type. I need to get the Hours and Minutes ago

Thank you.

View 1 Replies View Related

Convert Minutes To Hours

Feb 24, 2006

hi,

I want to convert minutes to hours. for example field_minutes=130minutes to 2:10 hours...

select field_minutes from table---> how can I do?

View 3 Replies View Related

Comparing Dates(Minutes, Hours Etc)

Jan 30, 2006

guys - is this a decent query to pull all columns (dateCreate)
that have a timestamp less than five minutes?
i know its simple, but i've never done a date compare with minutes or hours
in sql server
thanks
rik:o



select top 10 * from ptpuritm
where datediff(MINUTE,dateCreate,getdate()) <=5



select top 10 * from ptpuritm
where datediff(MINUTE,dateCreate,current_timestamp) <=5

View 3 Replies View Related

Calculate Total Hours / Minutes?

Jul 5, 2014

need to calculate the total hours mintues in sql server and asp.net

View 11 Replies View Related

Decimal Time To Hours Minutes

Feb 3, 2014

I have a series of times in decimal 15 min slots. The data type is float and the field is the followng:

10
10.25
10.5
10.75
11
and so on

I would like to convert that to the hour and 15 minute slot

10:00:00
10:15:00
10:30:00
10:45:00
11:00:00

View 4 Replies View Related

Right Data Type To Store Hours And Minutes

Mar 1, 2007

Hello friends
what is the right datatype to store the hours and minutes part in the database?
i found some info which says we have to convert the duration(hrs and min) into minutes and then store
is it the right approach?
Regards
Sara

View 1 Replies View Related

Adding Hours, Minutes, Seconds (SQL 2000)

Feb 21, 2007

Hi There,

I would like to find the sum of a column with a date format of '01:10:10' which is the hours:minutes:seconds from multiple rows.

For instance, "01:50:10" + "01:20:5" = "3:10:15"

Any ideas?

Using SQL 2000

View 5 Replies View Related

Converting Value To Days,hours,minutes & Seconds

May 13, 2008

Hi Guys,

I have data in minutes which is integer value ex 14454.I wanto convert it to days,hours,minutes & seconds.
Is there any simple way?

Regards.

View 2 Replies View Related

Getting Date Difference Along With Day,hours,minutes,seconds

Dec 8, 2007

Hi All,
I want to get the date Difference with Day,hours,minutes,seconds of the given 2 dates.(Say the difference of

12/6/2007 7:00:00 AM, 12/8/2007 8:00:00 AM as 2 days 1:00:00)

Is there any inbuilt function in SSRS is available to implement this. Or any other way to do this.Please help me with this .Thanks in advance.

With Thanks
M.Mahendra



View 2 Replies View Related

Transact SQL :: Getting Time Difference In Hours And Minutes?

Jul 10, 2015

Currently my script is using the below mentioned query to find the time difference.

DATEDIFF(HH,DATEADD(SS,hcreacion,fcreacion) ,DATEADD(SS,hcerrar,fcreacion))

If there is 1 hr 30 minutes time difference, I am getting 2 hours as output. But we need 1.30 as output. is there any way to achieve this?

View 14 Replies View Related

TimeAttributeType Error When Add Hours, Minutes And Seconds

May 26, 2008

In BIDS, I created a time dimension using the wizard. Unfortunately, the template used by the wizard does not contain Hours, Minutes and Seconds; so, I added them using the designer. Now, when I try to build, deploy and process I get the error: Unable to find matching TimeAttributeType. Cannot anyone explain why this is happening and what can be done about? Is there a template available somewhere that does create time dimensions with time and not just dates?

View 5 Replies View Related

Returning Time Difference As Days/ Hours/ Minutes

Sep 16, 2005

I have written a function that returns the number of Days, Hours and minutes from a given number of minutes. On testinf the results are close but not quite there. Can anyone see where I have gone wrong or is there an easier way of doing this? Code is as follows:

CREATE FUNCTION dbo.GetTimeBetweenLong
(@StartTime DateTime, @EndTime DateTime, @CurrentDate DateTime)
RETURNS VarChar(50) AS
BEGIN
DECLARE @TotalTime Numeric
DECLARE @Minutes Numeric
DECLARE @Hours Numeric
DECLARE @Days Numeric
DECLARE @MinutesInDays Numeric

IF @EndTime IS NULL
BEGIN
SET @Days = DATEDIFF(Day, @StartTime, @CurrentDate)
SET @Hours = DATEDIFF(Hour, @StartTime, @CurrentDate) - (@Days * 24)
SET @Minutes = DATEDIFF(Minute, @StartTime, @CurrentDate) - ((@Days * 24)*60) - (@Hours * 60)
END
ELSE
BEGIN
SET @Days = DATEDIFF(Day, @StartTime, @EndTime)
SET @Hours = DATEDIFF(Hour, @StartTime, @EndTime) - (@Days * 24)
SET @Minutes = DATEDIFF(Minute, @StartTime, @EndTime) - ((@Days * 24)*60) - (@Hours * 60)
END

IF(@Days <0)
BEGIN
SET @Days = @Days - @Days - @Days
END

IF (@Hours < 0)
BEGIN
SET @Hours = @Hours - @Hours - @Hours
END

IF (@Minutes <0)
BEGIN
SET @Minutes = @Minutes - @Minutes - @Minutes
END

RETURN CONVERT(nVarChar(10),@Days) + ' Days, ' + CONVERT(nVarChar(5), @Hours) + ' Hours, ' + CONVERT(nVarCHar(5), @Minutes) + ' Mins'

END

View 1 Replies View Related

SQL Server 2012 :: How To Add Minutes To A Date Within Working Hours Only

Sep 4, 2014

I need to be able to add minutes to a datetime value, which only cover working hours.

I have a holiday table as below:

Examples: (dd/MM/yyyy hh:mm)
Date..........Description
01/01/2015 New Years Day
26/12/2014 Boxing Day
25/12/2014 Christmas Day
25/08/2014 August Bank Holiday

Our Business hours are 08:00-18:00 Mon-Fri (unless the day is in the holiday table)

Start Date............Minute to Add......Expected outcome
01/09/2014 10:00........30...................01/09/2014 10:30
01/09/2014 17:00........65...................02/09/2014 08:05
29/08/2014 17:00........65...................01/09/2014 08:05
22/08/2014 17:00........65...................26/08/2014 08:05
31/08/2014 02:30........65...................01/08/2014 09:05
01/09/2014 19:00........65...................02/08/2014 09:05
01/09/2014 10:00........3005...............08/09/2014 10:05
22/08/2014 17:00........3005...............01/09/2014 17:05

I have tried to create a function to do this (fn_pp_AddMinutesWithinWorkingHours(@StartDate,@Minutes)) but I am unable to come up with a solution which factors in everything correctly.

View 1 Replies View Related

Reporting Services Formatting Fields From Whole Minutes To Hours

Jun 6, 2007

Dear All,

I have a problem formatting a field in Reporting Services (minutes to hours).

I have a field called duration which stores time in whole minutes only. I can format this into hours within mssql using the following:

cast(sn.duration/60 as varchar(5)) + ':' + RIGHT('0' + cast(sn.duration%60 as varchar(2)), 2)

But I need to have totals and average columns in my report, which means that the data must come through to RS in the minutes format so I can perform the calculations there.

I have the first part (I think!!):

=string.format("{0:0}",Fields!SalesTime.Value / 60) + ":"

But I cannot get the minutes part working!



Any help would be gratefully received.



Dan

View 3 Replies View Related

Format An Date Diff Expression To Hours And Minutes

Apr 4, 2008

Hello,
I have this expression DATEDIFF(HOUR, startdate,enddate) which only shows the hours. I need to show the hours and minutes too , exp. 9.17. Any way to convert the expression to do this. The startdate and enddate fields are mm/dd/yyy hh:mms. I am using report builder.

View 9 Replies View Related

Transact SQL :: Convert Time In Hours And Minutes To Decimal

Jul 30, 2008

I am trying to convert hours and minutes to decimal and arrive at a sum of time taken. The column TotalTimeSpent is the diff in hours/mins between the Started and Ended times.

SELECT DATENAME(weekday, Started) AS Day,        C.Category,     ClientCode,Description,    dbo.FormatDateTime(Started, 'HH:MMS 12') as Started,    dbo.FormatDateTime(Ended, 'HH:MMS 12') as Ended, CONVERT(varchar,TimeTaken,108) AS TotalTimeSpentFROM dbo.Journal JLEFT OUTER JOIN dbo.Categories C ON J.CategoryID = C.CategoryIDWHERE--DATENAME(weekday, Started) =@Weekday  AND Started >= @StartDate ORDER BY Day, Category, Started

View 6 Replies View Related

DateDiff - Obtain Total Duration In Hours / Minutes And Seconds

Mar 2, 2014

Given the two datetimes below, what's the best way to obtain the total duration in hours, minutes and seconds (HH:mm:ss)?

Start Time: 2014-03-02 20:55:00.000
End Time: 2014-03-03 07:00:00.000

Duration = 10:05:00

View 6 Replies View Related

Changing Seconds To Hours And Minutes And Rounding To The Nearest 15 Minute.

Dec 6, 2007

I found in another forum that if I take the seconds and divide them by 15 then round up and multiply them by 4 I can get this done, but I can't figure out how to work it into my select statement. Anyhelp would be greatly appreciated. dbo.SLPTRANS.TimeSpent is the field I am trying to convert.

SELECT dbo.SLPTRANS.ClientID, SUM(dbo.SLPTRANS.TransValue) AS Expr1, dbo.SLPTRANS.TimeSpent AS Expr2
FROM dbo.SLPTRANS INNER JOIN
dbo.INVOICE ON dbo.SLPTRANS.InvoiceID = dbo.INVOICE.RecordID
GROUP BY dbo.SLPTRANS.ClientID
HAVING (dbo.SLPTRANS.ClientID = 405)

View 4 Replies View Related

Convert Char Datatype To Datetime Datatype

Sep 17, 2003

Database is SQL Server 2000

I have a field in a table that stores date of birth. The field's datatype is char(6) and looks like this: 091703 (mmddyy). I want to convert this value to a datetime datatype.

What is the syntax to convert char(6) to datetime?

Thank you in advance.

View 1 Replies View Related

What Is The Right Datatype To Store Hours Up To The Minute Precision?

Jan 28, 2006

Right now the database I am working with is storing time inan Integer data type and is storing the time value in seconds.The application does not allow entering seconds. It acceptsminutes and hours.I have a report where it is doing:SELECT SUM(TIMEENTERED)and the SUM is *blowing* up as the SUM is reachingthe BIGINT range.I can fix the problem by changing all codes to:SELECT SUM(CAST(TIMEENTERED AS BIGINT))But now that I ran into this problem I want to find outif storing the time in seconds using INTEGER datatype is the best solution?I've been searching this newsgroup and other placesthe whole day. I even ran into my own three year oldpost. Three years ago my problem was data migrationrelated and now it is more of performance related thananything else.http://groups.google.com/groups?as_...y=2006&safe=offI could not find this specific topic in SQL books likeSQL for Smarties 2005 by Joe Celko (very good stuff ontemporal topics but nothing specific to my question),or Inside SQL Server 2000.Which data type would be ideal and why?smalldatetime?integer?decimal?float?The type of operations that are being done in the databaseare:1- Entering time in hours on work done on a taskFor the data entry part, the application accepts2.5 as 2 and a half hours and it is storing2.5 * 3600 = 9000 seconds.It also accepts entering 2:30 as 2 hours and30 minutes and again storing 9000 seconds.I even saw a page where you can enter clocktime: I worked from 9:30AM to 12:45PMas an exampleWhen i checked the underlying table(s) I sawthat the ENTEREDTIME is always the durationin seconds. So the data entry can either be2.5 hours where ENTEREDTIME = 9000 secondsor9:00AM to 11:30AMwhere STARTDATE is today's date for examplestored as 1/27/2005 09:00AMand where ENTEREDTIME = 9000 seconds2- All kinds of reports showing total time in hoursfor example: Project1 = 18.5 hoursThe code in the SP are all like:SUM(ENTEREDTIME) / CAST(3600 AS DECIMAL(6,2))AS TOTALTIME3- I am sure a lot of other arithmetic calculations arebeing done with this ENTEREDTIME field.What would be the best way to store hours/minutesbased on how we are using Time in the database?Either I will stick with Integer but store in minutestime instead of calculating in seconds and most likelyupdate all the SUM(ENTEREDTIME) toSUM(CAST(ENTEREDTIME AS BIGINT))or I will switch to storing in decimal/float andmaybe avoid doing :SUM(ENTEREDTIME) / CAST(3600 AS DECIMAL(6,2))AS TOTALTIMEsince the ENTEREDTIME would already be storedin hours time.or I will use DATETIME since in the cases ofI worked from 9:00AM to 11:30AMI have to have a separate column to store the date also.I am a little confused I am hoping I will get some helpfrom you and maybe if I can't find the best solution, atleast eliminate the NOT so good ones I am thinking of.Thank you

View 1 Replies View Related

Datetime To Minutes?

Aug 3, 2004

hey all, i need to find the ratio of difference in 2 datetime variables and the difference of another 2 datetime vars. I figured the best way to do it is to convert the difference in both numerator and denominator to number of minutes.

can anyone help ??

View 1 Replies View Related

SQl Server Backup Takes 2 Hours To Run But 12 Minutes After A Server Reboot(?)

Sep 19, 2007

Sorry i think i may have posted this in the incorrect forum before - if i have done it again here can someone tell me where i should post this please, thanks:

Hi,
we are having problems with a server Intel RZeon 3ghz, 3gb ram running 2003 service pack 2 with a 70gb drive and and 400 gb drive all with adequate free space. There are 6 hard disks in total and i assume operating at least RAID 5. We have SQL2000 server with a few standard sized databases and a connection to one other server.

A few months ago the back up of SQL server databases started taking 4- 5 hours when before it took 20 minutes. We had actually lost one of our disks in the RAID array and it before this was spotted by our engineers we reindexed the sql databases and defragged both 70gbC: and D: 400gb drives hoping to correct this slow down. Unfortunately the new disk had not been correctly seated and this was why it was taking 4-5 hours. After fixing the disk the backups took 12 minutes again but then started taking 2-3 hours after a few days.

The reindex/defrag did seem to improve the speed of the backups to 12 minutes (from 20 minutes) when the backup did function correctly (also the sql databases' performance improved). However the backups only take 12 minutes after a server reboot - this can last from only 2, up to 5 backups(days) in a row before a slow down to 2-3 hours and again only a reboot will sort out this problem.

NB this intermittent slowdown only occurred after the disk failure.

We have tried monitoring SQL server and can find no CPU/RAM intensive clashes or long running jobs interferring with the back up. Does anyone know what might be going on here? and if there are any server monitoring tools that may help us discover what is causing this problem ?

thanks for your help
best regards
kevin

View 11 Replies View Related

How Can I Convert Datetime To Number Of Minutes

Oct 9, 2007

I have a column in a table that stores the number of hours a task took to do. The column TaskDuration is a datetime datatype. I need to convert the hours to something that can be summed. Does anyone how this can be done? I tried CONVERT(nvarchar(5), tblTasks.TaskDuration, 108) but of course the nvarchar(5) cannot be summed. Maybe there is a way to convert the time portion to minutes and divide it by 60, anyway if someone can offer some help I appreciate it.

View 5 Replies View Related

Dealing W/ Minutes In DateTime Field

Apr 16, 2004

If I subtract 14 days from a datetime field, will the time of day that I run this query affect the resultset? I am running the query during "normal business hours", 8 am - 5 pm, and the records are entered during this time frame as well.

ddave

View 6 Replies View Related

T-SQL (SS2K8) :: Get Difference In Minutes Between 2 Datetime

Apr 26, 2014

I've table and data as follow,
declare @tAccount table
(
isLocked bit,
LastLockoutDate datetime,
currentDte dateTime
)

insert into @tAccount values('true','2014-04-26 16:11:25.337',getdate())
Let's say, current data as follow,
isLocked| LastLockoutDate| currentDte
12014-04-26 16:11:25.3372014-04-27 01:45:15.053

How to get different in minutes between currentDate and LastLockoutDate? Mean, currentDate - LastLockoutDate.

View 3 Replies View Related

List All Minutes Between Two DATETIME Values

May 22, 2008

Hi, does anyone know a SQL statement that will take two DATETIME values and list all minutes in between them like so:

START VALUE: 5/22/2008 10:00
END VALUE: 5/22/2008 10:10

RESULT:
5/22/2008 10:00
5/22/2008 10:01
5/22/2008 10:02
5/22/2008 10:03
5/22/2008 10:04
5/22/2008 10:05
5/22/2008 10:06
5/22/2008 10:07
5/22/2008 10:08
5/22/2008 10:09
5/22/2008 10:10

Thanks!

View 8 Replies View Related

Finding Minutes In Datetime Intervals [SQL Server2005]

May 29, 2008

[SQL Server 2005]


In a report there are following in parameters: from date, to date, from time and to time.

I need to match these search criteria€™s against start time and stop time in assignments.
The trick: How to write SQL that meets all different cases that can arise.

The query need's to traverse through every assignment,
and see if its start and stop time is in the interval given by the user.

It should then return the minutes from the assignment that is within the interval.



I'm thinking of packaging the minute "extracting" logic in a Scalar-valued function.

It should then take the in parameters from the user, and start time and stop time from the assignment as arguments.

To consider: Crossing midnight.



E.g. the user puts in

From date: 2008-05-24

From time: 22:00:00

To date: 2008-05-26

To time: 02:00:00



Since the user wants to evaluate a time span that crosses midnight,

I'll have to look in to time spans like:

2008-05-24 22:00:00 - 2008-05-24 23:59:59

2008-05-25 00:00:00 - 2008-05-25 02:00:00

2008-05-25 22:00:00 - 2008-05-25 23:59:59

2008-05-26 00:00:00 - 2008-05-26 02:00:00



Furthermore the start- and stop time can be partially in the above interval.

E.g. an assignment starts 2008-05-24 21:46:11 and stops 2008-05-24 22:36:05.

This would then yield from the time spans above 36 minutes.

The combinations seem never-ending€¦

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved