在第4行代码(忽略空格和注释)以及我正在计算2个日期之间的月份差异.这有效,但看起来有点hacky.有没有更好的办法?
int handleAllowance(LocalDate today) {
int allowance = membership.allowance();
if (allowance == 0) return 0;
// if update was last month (or earlier)
int months = today.monthOfYear().getMaximumValue() - today.monthOfYear().getMinimumValue(); // yeah, 12, but just to be 100% correct :-)
int curMonth = (today.getYear() * months) + today. getMonthOfYear();
int updMonth = (lastAllowanceUpdate.getYear() * months) + lastAllowanceUpdate.getMonthOfYear();
if (curMonth > updMonth) {
// ...and if today is on or past update day
int updateDay = Math.min(allowanceDay, today.dayOfMonth().getMaximumValue());
if (today.getDayOfMonth() >= updateDay) …Run Code Online (Sandbox Code Playgroud) 我是Spark SQL的新手。我们正在将数据从SQL Server迁移到Databricks。我正在使用SPARK SQL。您能否建议以下日期函数在SPARK sql中实现以下功能?我可以看到datediff在spark sql中仅给出几天。
DATEDIFF(年,StartDate,EndDate)DATEDIFF(月,StartDate,EndDate)DATEDIFF(四分之一,StartDate,EndDate)
我想过滤数据集以查找特定日期之前的所有日期。具体来说是当前日期前 1 天。
我尝试了下面的代码:
df = df.filter(F.col('date') <= F.current_date() - 1)
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
u"cannot resolve '(current_date() - 1)' due to data type mismatch: differing types in '(current_date() - 1)' (date and int)
Run Code Online (Sandbox Code Playgroud) 我正在尝试做我认为是一个简单的日期差异函数,但由于某种原因,我的单位值被读取为一列(“dd”),所以我不断收到无法解决的列错误
我正在使用 AWS Athena
我的代码是这样的
SELECT "reservations"."id" "Booking_ID"
, "reservations"."bookingid" "Booking_Code"
, "reservations"."property"."id" "Property_id"
, CAST("from_iso8601_timestamp"("reservations"."created") AS date) "Created"
, CAST("from_iso8601_timestamp"("reservations"."arrival") AS date) "Arrival"
, CAST("from_iso8601_timestamp"("reservations"."departure") AS date) "Departure"
, CAST("from_iso8601_timestamp"("reservations"."modified") AS date) "Modified"
, date_diff("dd", CAST("from_iso8601_timestamp"("reservations"."created") AS date), CAST("from_iso8601_timestamp"("reservations"."arrival") AS date)) "LoS"
FROM
"database".reservations
LIMIT 5;
Run Code Online (Sandbox Code Playgroud)
我试图从“创建日期”和“到达日期”中获得天数差异
我已经用 DD,"DD","dd",dd,Day,day,"day" 尝试了 date_diff 并且我得到了同样的错误。
我有关于datediffMYSQL函数的问题,我可以使用它而且很简单.但我不明白如何使用它来收集表字段内的差异.例如
我有一个列dob,我想编写一个类似的查询
select dateDiff(current_timeStamp,dob)
from sometable 'here dob is the table column
Run Code Online (Sandbox Code Playgroud)
我的意思是我希望从当前日期时间到表字段dob的差异,每个查询结果是差异,用户的年龄.
我有2个字符串,strStartTime和strEndTime.
strStartTime ="12:32:54"strEndTime ="12:33:05"
我想知道strStartTime和strEndTime之间经过了多少秒,所以我这样做了:
Dim dtDuration as date
dtDuration = DateDiff("s", CDate(strStartTime), CDate(strEndTime))
Run Code Online (Sandbox Code Playgroud)
我得到的结果是当地观察窗口中的dtDuration ="#1/10/1900#".
为什么会这样?如何在开始和结束时间之间经过的11秒内将dtDuration设置为等于11?
我遇到DateDiff函数的问题.我想弄清楚两个日期/时间之间的差异.我已经阅读了这篇文章(在Javascript中计算日期差异的最佳方法是什么),我也看了这个教程(http://www.javascriptkit.com/javatutors/datedifference.shtml),但我似乎无法得到它.
这是我试图开始工作但没有成功.有人可以告诉我我在做什么以及如何简化这一点.似乎有点过度编码......?
//Set the two dates
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var currDate = month + "/" + day + "/" + year;
var iniremDate = "8/10/2012";
//Show the dates subtracted
document.write('DateDiff is: ' + currDate - iniremDate);
//Try this function...
function DateDiff(date1, date2) {
return date1.getTime() - date2.getTime();
}
//Print the results of DateDiff
document.write (DateDiff(iniremDate, currDate);
Run Code Online (Sandbox Code Playgroud) 我收到报告,其中数据ETL自动发送到数据库.我提取并转换了一些数据,将其加载到其他地方.我需要做的一件事是a,DATEDIFF但年份需要准确(即4.6年,而不是四舍五入.
以下是我的脚本:
select *, DATEDIFF (yy, Begin_date, GETDATE()) AS 'Age in Years'
from Report_Stage;
Run Code Online (Sandbox Code Playgroud)
该'Age_In_Years'列正在舍入.我如何获得多年的确切日期?
有很多答案,但我无法找到与我的情况兼容.我需要找到8小时的差异以及日期变化.就像时间大于8小时然后不执行某些事情.
我们有没有LocalDateTime在Java-8中实现相同的方法?
我试过使用以下但无法实现相同的目标.
LocalDateTime fromDateTime = LocalDateTime.of(2017, 07, 07, 07, 00, 55);
LocalDateTime toDateTime = LocalDateTime.now();
LocalDateTime tempDateTime = LocalDateTime.from(fromDateTime);
long years = tempDateTime.until(toDateTime, ChronoUnit.YEARS);
tempDateTime = tempDateTime.plusYears(years);
long months = tempDateTime.until(toDateTime, ChronoUnit.MONTHS);
tempDateTime = tempDateTime.plusMonths(months);
long days = tempDateTime.until(toDateTime, ChronoUnit.DAYS);
tempDateTime = tempDateTime.plusDays(days);
long hours = tempDateTime.until(toDateTime, ChronoUnit.HOURS);
tempDateTime = tempDateTime.plusHours(hours);
long minutes = tempDateTime.until(toDateTime, ChronoUnit.MINUTES);
tempDateTime = tempDateTime.plusMinutes(minutes);
long seconds = tempDateTime.until(toDateTime, ChronoUnit.SECONDS);
System.out.println("" + java.time.Duration.between(tempDateTime, toDateTime).toHours());
System.out.println(years + " years "
+ months + " …Run Code Online (Sandbox Code Playgroud) 有没有什么方法可以计算雪花中两个日期之间的工作日而无需创建日历表,仅使用“datediff”函数
datediff ×10
date ×6
sql ×3
calendar ×1
databricks ×1
datetime ×1
java ×1
java-8 ×1
javascript ×1
jodatime ×1
mysql ×1
presto ×1
pyspark ×1
python ×1
snowflake-cloud-data-platform ×1
sql-server ×1
subtraction ×1
vba ×1