datediff

DATEDIFF() Parameter Issue

橙三吉。 提交于 2019-12-12 07:15:04
问题 The old DATEDIFF() allowed users to use 3 parameters, and I was trying to do this so I could get hours out of my DATEDIFF rather than days, (I'm trying to show hours since a post). In my database I'm using a TIMESTAMP and this line of code to pull a value, and obviously it doesn't work because I have the extra parameter. Once I remove the 'hour' or 'hh' the query runs and returns a value in days. SELECT DATEDIFF(hour, CURDATE(), (SELECT Post_Date FROM Post_T WHERE pk_PostID = 1) ) Is there an

SQL Query DATEDIFF date time fields result in minutes

无人久伴 提交于 2019-12-12 06:38:42
问题 Can anyone tell me how to write the SQL Query to calculate the time difference between 2 columns that are stored as DATETIME columns and get the result in minutes... For example: Table structure ID, start-time, end-time I want to do a select on a specific ID and perform a calculation of the end-time - start-time and return the result in minutes only. 回答1: MySql : TimeStampDiff: SELECT TIMESTAMPDIFF(MINUTE, start_time, end_time) FROM MyTable WHERE ID = 1; SqlServer: DATEDIFF SELECT DATEDIFF(n,

PHP date_diff function broken?

谁都会走 提交于 2019-12-12 03:57:39
问题 Consider these two dates 2017/4/14, 2017/6/3 Using date_diff in php gives me this object(DateInterval)[6] public 'y' => int 0 public 'm' => int 1 public 'd' => int 20 public 'h' => int 0 public 'i' => int 0 public 's' => int 0 public 'weekday' => int 0 public 'weekday_behavior' => int 0 public 'first_last_day_of' => int 0 public 'invert' => int 0 public 'days' => int 50 public 'special_type' => int 0 public 'special_amount' => int 0 public 'have_weekday_relative' => int 0 public 'have_special

Datediff GETDATE Add

拈花ヽ惹草 提交于 2019-12-12 03:09:18
问题 In this type of code, AND Orders.ShipDate >= DATEADD(Day, Datediff(Day,0, GetDate() -6), 0) It supposed to pull records with the date 6 days ago, until today. How can I make it pull records from 7 days ago until yesterday? I know changing -6 to -7 will pull records from 7 days ago, but which variable is the end of the date span so I can change it to -1 ? 回答1: It's not a date span. The condition you have there is really only one condition: greater than. The right side of the greater than is 6

Teradata DATEDIFF Error

↘锁芯ラ 提交于 2019-12-12 02:29:05
问题 Hi i am getting an error as expected something like END keyword between DATEDIFF and ( for the below statement under select case when CC.CASE_STS_CD in ( 'Closed', 'Auto Closed') then DATEDIFF(second,CC.REC_DTTM_PST,CC.CRT_DTTM_PST) end as CASE_RES_DUR_IN_SECS, 回答1: Assuming that your fields are DATE datatype (otherwise you'll need to cast): SELECT CASE WHEN CC.CASE_STS_CD IN ('Closed','Auto Closed') THEN (CC.REC_DTTM_PST - CC.CRT_DTTM_PST) * 86400 END AS CASE_RES_DUR_IN_SECS 回答2: There's no

Calculate Number of Occupied Days within a date period using MySQL and PHP

柔情痞子 提交于 2019-12-12 01:28:04
问题 I have an apartment booking system and need to generate a report of number of occcupied days vs. unoccupied days within a date period on a property by property basis. Bearing in mind within the chosen period that some bookings may start before and/or end after the start / end date respectivley. I found this - MySQL Number of Days inside a DateRange, inside a month (Booking Table) - which is along the right lines, but I don't want it on a fixed, month by month basis but rather between two

DATEDIFF - Replace NULL with NOW()

↘锁芯ラ 提交于 2019-12-11 12:26:20
问题 I got following SQL Query SELECT e.id, c.name, e.location, e.designation, e.time_period_from, e.time_period_to, DATEDIFF(e.time_period_to, time_period_from) AS tenure_in_days FROM employment e LEFT JOIN company c ON (c.id = e.company_id) LIMIT 0, 10 This is working perfectly, i have a scenario where time_period_to can have NULL values, in this case, i want to replace it with current date. Here is what i tried. SELECT e.id, c.name, e.location, e.designation, e.time_period_from, e.time_period

SQL - Difference between odd/even columns into another column

ⅰ亾dé卋堺 提交于 2019-12-11 11:46:35
问题 I have a table which consists of the following data. Employee TimeRegister1 TimeRegister2 TimeRegister3 TimeRegister4 77 2014-04-01 11:51:43.000 2014-04-01 14:03:52.000 2014-04-01 14:17:01.000 2014-04-01 16:01:12.000 77 2014-04-03 09:48:33.000 2014-04-03 12:13:43.000 2014-04-03 12:22:27.000 2014-04-03 14:03:43.000 181 2014-04-02 08:24:34.000 2014-04-02 13:01:10.000 2014-04-02 14:30:31.000 2014-04-02 18:04:04.000 What I need is to write, on another column, the total calculated from the

get datediff hours in decimal sql server

让人想犯罪 __ 提交于 2019-12-11 09:12:53
问题 i need query to get total hours in decimal value this is my query so far: declare @start as time; declare @end as time; declare @total as decimal(18, 2); set @start = '17:00:00' set @end = '18:30:00' set @total = datediff(minute, @start, @end)/60 print @total the query give me integer value, although the @total parameter is a decimal. I don't know how to get the decimal value. please help me, and thank you in advance. 回答1: Try divide by 60.0. This will provide the required precision An int

Sql Server 2008 Exclude Company Holiday from DateDiff

江枫思渺然 提交于 2019-12-11 06:15:11
问题 I have three tables, One of which is a master calendar that houses an indicator for company Holidays. I would like to exlude Holiday from my DateDiff calculation. Below is what I have... alert date 12/23/16 complete date 12/28/16 company Holiday 12/26/16 Need to exlude from DateDIff calculation --My calculation shows 3 business days it should exclude 12/26/16 = 2 business days DATEDIFF(DD,A.ALERTS_CREATE_DT,S.CreatedDate) -(DATEDIFF(WK,A.ALERTS_CREATE_DT,S.CreatedDate) * 2) --HOW MANY WEEKEND