datediff

DATEDIFF in SPARK SQl

我与影子孤独终老i 提交于 2019-12-04 03:08:10
I am new to Spark SQL. We are migrating data from SQL server to Databricks. I am using SPARK SQL . Can you please suggest how to achieve below functionality in SPARK sql for the below datefunctions. I can see datediff gives only days in spark sql. DATEDIFF(YEAR,StartDate,EndDate) DATEDIFF(Month,StartDate,EndDate) DATEDIFF(Quarter,StartDate,EndDate) As you have mentioned SparkSQL does support DATEDIFF but for days only. I would also be careful as it seems the parameters are the opposite way round for Spark, ie --SQL Server DATEDIFF ( datepart , startdate , enddate ) --Spark DATEDIFF ( enddate ,

How to get current date/time as a date object in PHP

南楼画角 提交于 2019-12-03 23:03:53
How do you get today's date, as a date object? I'm trying to compute the difference between some start date and today. The following will not work, because getdate() returns an array and not a date object: $today = getdate(); $start = date_create('06/20/2012'); $diff = date_diff($start, $today); echo($today . '<br/>' . $start . '<br/>' . $diff); Output: Array ( [seconds] => 8 [minutes] => 1 [hours] => 16 [mday] => 11 [wday] => 1 [mon] => 6 [year] => 2012 [yday] => 162 [weekday] => Monday [month] => June [0] => 1339455668 ) DateTime Object ( [date] => 2012-06-20 00:00:00 [timezone_type] => 3

Difference in Days between two Java dates?

无人久伴 提交于 2019-12-03 21:16:26
问题 I want to get the difference between two Java Date objects. I've used Joda-Time library. But the problem is that I'm getting the Days greater difference than that of actual day difference. Here's my code snippet: DateFormat formatter = new SimpleDateFormat("mm/dd/yyyy"); Date someDate=new Date(); Date today = Calendar.getInstance().getTime(); try { someDate = formatter.parse("06/22/2010"); } catch(ParseException pe) { System.out.println("Parser Exception"); } int days = Days.daysBetween(new

Count the number of rows in 30 day bins

穿精又带淫゛_ 提交于 2019-12-03 15:52:16
Each row in my table has a date time stamp, and I wish to query the database from now, to count how many rows are in the last 30 days, the 30 days before that and so on. Until there is a 30 day bin going back to the start of the table. I have successfully carried out this query by using Python and making several queries. But I'm almost certain that it can be done in one single MySQL query. Phil Frost No stored procedures, temporary tables, only one query, and an efficient execution plan given an index on the date column: select subdate( '2012-12-31', floor(dateDiff('2012-12-31',

date_diff() expects parameter 1 to be DateTimeInterface, string given

霸气de小男生 提交于 2019-12-03 12:44:10
i got this problem and i don't know what to do... they have thesame format $date_expire = '2014-08-06 00:00:00'; $date1 = date("Y-m-d G:i:s"); $date2 = date_create($date_expire); $diff = date_diff($date1, $date2); //this line makes error.. Rikesh Because you are passing string whereas date_diff expects datetime object, $date_expire = '2014-08-06 00:00:00'; $date = new DateTime($date_expire); $now = new DateTime(); echo $date->diff($now)->format("%d days, %h hours and %i minuts"); DEMO . 来源: https://stackoverflow.com/questions/24608529/date-diff-expects-parameter-1-to-be-datetimeinterface

Difference in days between 2 dates Oracle SQL

谁说我不能喝 提交于 2019-12-02 14:41:08
问题 Alright, so I've checked many many many other posts on stackoverflow to see if this is mentioned anywhere, and the answers provided don't quite make sense to me...I'm thinking they're talking about something completely different. Here's what I want to do, using Oracle SQL Developer: -Retrieve entries from purch_date -Get the difference IN DAYS between the purch_date and Christmas of the CURRENT YEAR * *So, therefore '2012' can't be hard-coded in there. I need to retrieve it. Here's the query

VBScript DateDiff month

守給你的承諾、 提交于 2019-12-02 10:02:59
问题 I am having a problem about getting the month datedifference between two dates. Here is a sample: DateDiff("m","2014-10-17","2014-10-30") The above code returns 0 months since it is less than a month. But, DateDiff("m","2014-10-17","2014-11-01") returns 1 which should not be since it is still 15 days. My problem is I want to see if these two dates already exceed a month but it seems that it calculates 1 month only when the month part of the date is changed. 回答1: DateDiff calculates the span

PHP date_sub. can't substract today and date

守給你的承諾、 提交于 2019-12-02 07:43:45
I am trying to output number of days between today and the date I enter so I have a problem I encounter error: "Warning: date_diff() expects parameter 2 to be DateTimeInterface" So what's the problem ? <?php $today=date("y-m-d"); $date=date_create("2016-09-16"); echo date_diff($date,$today); ?> Your problem lies in that when using date_diff you have to make sure that you're comparing objects that are actual date objects. Also the return type for date_diff is a DateInterval object. You're treating it as a string. $today = new DateTime(); // $today is a DateTime object $date = new DateTime("2016

Calculating difference on datetime row betwen rows on the same table

廉价感情. 提交于 2019-12-02 07:31:26
I have table that holds records with tasks, status and time when triggered: Table tblwork: +-------------+------------+---------------------+-----+ | task | status | stime | id | +-------------+------------+---------------------+-----+ | A | 1 | 2018-03-07 20:00:00 | 1 | | A | 2 | 2018-03-07 20:30:00 | 2 | | A | 1 | 2018-03-07 21:00:00 | 3 | | A | 3 | 2018-03-07 21:30:00 | 4 | | B | 1 | 2018-03-07 22:30:00 | 5 | | B | 3 | 2018-03-07 23:30:00 | 6 | +-------------+------------+---------------------+-----+ Status 1 means start, 2 - pause, 3 - end Then I need to calculate how much time is spent

DateDiff Function

懵懂的女人 提交于 2019-12-02 07:09:14
问题 I am trying some examples for DateDiff Function SELECT DATEDIFF(day,'2008-06-05','2008-08-05') AS DiffDate This statement gives me an error From keyword not found where expected. Why do I get this error and how can I solve it? Also, when I try this : SELECT DATEDIFF(day,datebegin,datestop) From table; I get this error "datediff" invalid identifier . How can I get day difference? 回答1: What database are you using? A google search gave me this: http://www.mssqltips.com/sqlservertip/2508/sql