datediff

SQL Server 2012 Insert DATEDIFF into column trigger whenever a new record is inserted

拥有回忆 提交于 2019-12-11 04:08:51
问题 Table CREATE TABLE CurrentApplication ( StartDate datetime NOT NULL, EndDate datetime NOT NULL, NoOfDays integer, StaffID integer NOT NULL, AppStatus varchar(30) NOT NULL DEFAULT 'PENDING' ) Trigger CREATE TRIGGER InsertNoOfDays ON CurrentApplication AFTER INSERT AS BEGIN DECLARE @temp INT SELECT @temp = DATEDIFF(day, EndDate, StartDate) FROM inserted INSERT INTO CurrentApplication(NoOfDays) VALUES (@temp) --SELECT StaffID = inserted.StaffID --FROM inserted -- INSERT INTO CurrentApplication

Compare difference between two dates using JPA Criteria Query

泄露秘密 提交于 2019-12-11 03:22:23
问题 I am using MySQL as a backend for my application. I want to execute query below using JPA Criteria Query. SELECT * FROM table1 t1 WHERE datediff(now(), t1.created) >= 20; Note: Type of created is TIMESTAMP I want Criteria Query like: CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); // select CriteriaQuery<Table1> query = cb.createQuery(Table1.class); // from Root<Table1> root = query.from(Table1.class); // where List<Predicate> predicates = new ArrayList<Predicate>(); // TODO:

SQL Server: difference in days for two dates in separate rows

不想你离开。 提交于 2019-12-11 02:37:35
问题 I am using SQL Server 2012 and working an a report currently that is asking me to find the difference in days between two dates. Basically, for a particular ReportID , I'm trying to find the difference in days between the ( ReportCompletedDate when the ReportType = 'PaperReceived' ) - ( ReportCompletedDate when the ReportType = 'Form Completed' ) I tried to give some records below... ReportID ReportType ReportCompletedDate ------------------------------------------------- 450 PaperReceived 9

Time difference between dateTime fields SSRS

不想你离开。 提交于 2019-12-10 16:12:31
问题 I have two datetime fields and I need to show the difference between them. I've used this expression to calculate it: =DateDiff("n", Fields!hra_atncion.Value, Fields!fcha_incio.Value) The result column should be on HH:mm , but the result is a Long expression type. Something like 428011156 Any answer will be apreciated! UPDATE 21/11/2013 How I obtain the time difference in minutes between 12-11-2013 20:00 and 14-11-2013 08:00 ? 回答1: I think, you should try this expression: =Datediff("h",Fields

SQL query to get DateDiff of the last two records

笑着哭i 提交于 2019-12-10 15:22:09
问题 I have a table called Event with eventNum as the primary key and date as a datetime2(7) in SQL Server 2008 R2. I am trying to get the date of the last two rows in the table and get the difference in minutes. This is what I currently have: Select DATEDIFF(MI, e.date,(Select e2.date from Event e2 where eventNum = (Select MAX(e2.eventNum)))) From Event e Where eventNum = (Select MAX(e.eventNum)-1 from e) and I get this error: Invalid column name 'Select eventNum from Event Where eventNum =

How to calculate difference between two datetime in ElasticSearch

我与影子孤独终老i 提交于 2019-12-10 15:07:20
问题 I'm working with ES and I need a query that returns the difference between two datetime (mysql timediff), but have not found any function of ES to do that. Someone who can help me? MySQL Query SELECT SEC_TO_TIME( AVG( TIME_TO_SEC( TIMEDIFF(r.acctstoptime,r.acctstarttime) ) ) ) as average_access FROM radacct Thanks! 回答1: Your best best is scripted fields. The above search query should work , provided you have enabled dynamic scripting and these date fields are defined as date in the mapping. {

T-SQL DateDiff - partition by “full hours ago”, rather than “times minutes turned 00 since”

安稳与你 提交于 2019-12-10 14:31:02
问题 I have a table with timestamps, and I want to partition this table into hour-long intervals, starting at now and going backwards a couple of hours. I'm unable to get the results I need with the T-SQL DATEDIFF function, since it counts the number of times the minute hand passes 12 between the two dates - I want the number of times them minute hand passes where it is now between the timestamp and now. Is there a straightforward way to do this in T-SQL? Update: In response to comments, here's

Updating year in datetime variable

爷,独闯天下 提交于 2019-12-10 13:08:03
问题 I'm playing around with manipulating a datetime variable. I can't seem to find a way to update a datetime variable year to the current year. For example I have 2007-12-01 00:00:00.000 But I would like that to be 2012-12-01 00:00:00.000 (The current year were in) I've been playing with datediff , but I can't seem to nail it. Any advice would be appreciated. Thanks 回答1: DECLARE @date datetime = '2007-01-09T12:34:56' SELECT @date = DATEADD(yyyy, DATEDIFF(yyyy, @date, GETDATE()), @date) SELECT

PHP Date diff with a difference

倖福魔咒の 提交于 2019-12-10 11:02:03
问题 Please bear with me as I try to explain my predicament. I need to somehow get the difference between two dates by reversing a function I have to add months and years? Problem The date add function provided with PHP >= 5.3 does not add dates in the manner I require. Example: +3 Months to 30Nov = 2Mar Solution I use the function below (code ref 2) to produce the results I need. Example: +3 Months to 30Nov = 28Feb However when using the below (code ref 1) to calculate the difference it does so

Get records based on Current Date and Configured Data

微笑、不失礼 提交于 2019-12-10 09:32:13
问题 I am working on automating the SMS sending part in my web application. SQL Fiddle Link DurationType table stores whether the sms should be sent out an interval of Hours, Days, Weeks, Months. Referred in SMSConfiguration CREATE TABLE [dbo].[DurationType]( [Id] [int] NOT NULL PRIMARY KEY, [DurationType] VARCHAR(10) NOT NULL ) Bookings table Contains the original Bookings data. For this booking I need to send the SMS based on configuration. SMS Configuration . Which defines the configuration for