请设定下表。当我使用datediff(StartDate, SubmittedOn) 时,我只得到 int 类型的天数,这是不准确的。那么如何获得迟到的呢?谢谢。
StartDate SubmittedOn what I get using datediff what I am tring to get
9/7/2016 13:12 9/1/2016 0:00 6 6.550520833
9/1/2016 16:22 9/1/2016 0:00 0 0.682048611
9/9/2016 13:30 9/1/2016 0:00 8 8.562708333
9/9/2016 13:31 9/1/2016 0:00 8 8.563472222
9/9/2016 16:08 9/1/2016 0:00 8 8.672407407
9/2/2016 16:08 9/1/2016 0:00 1 1.672685185
9/2/2016 16:01 9/1/2016 0:00 1 1.667465278
Run Code Online (Sandbox Code Playgroud) 我有 Pandas 背景,对 Spark 很陌生。我有一个数据框,其中有id, dob,age作为列。我想从用户的年龄中获取他的年龄dob(在某些情况age下列为 NULL)。
+----+------+----------+
| id | age | dob |
+----+------+----------+
| 1 | 24 | NULL |
| 2 | 25 | NULL |
| 3 | NULL | 1/1/1973 |
| 4 | NULL | 6/6/1980 |
| 5 | 46 | |
| 6 | NULL | 1/1/1971 |
+----+------+----------+
Run Code Online (Sandbox Code Playgroud)
我想要一个新列来计算从dob当前日期开始的年龄。
我尝试了这个,但没有得到任何结果:
df.withColumn("diff",
datediff(to_date(lit("01-06-2020")),
to_date(unix_timestamp('dob', "dd-MM-yyyy").cast("timestamp")))).show()
Run Code Online (Sandbox Code Playgroud) 我希望创建一个获取上个月的第一个和最后一个日期的方法,以便我可以使用 Between 语句执行 WHERE 子句。它看起来像这样
WHERE
FirstSold_Date BETWEEN first_day_previous_month AND last_day_previous_month
Run Code Online (Sandbox Code Playgroud) 我对 Java 平台非常初学者和陌生。我有以下 3 个简单的 Java 日期差计算函数。我想在所有 3 种方法中排除以下计算中的周末。任何人都可以帮助如何在以下 dateDiff 计算中排除周末吗?
public static String getDatesDiff(String date1, String date2) {
String timeDiff = "";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date d1 = null;
Date d2 = null;
try {
d1 = format.parse(date1);
d2 = format.parse(date2);
long diff = d2.getTime() - d1.getTime();
timeDiff = ""+diff;
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return timeDiff;
}
Run Code Online (Sandbox Code Playgroud)
public static String getDatesDiffAsDays(String date1, String date2) {
String timeDiff = ""; …Run Code Online (Sandbox Code Playgroud) 反正有没有在PHP中找到日期差异?我有从2003-10-17到2004-03-24的输入.我需要结果这两天内有多少天.假如224天,我只需要几天的输出.
我通过mysql找到解决方案,但我需要在PHP中.有人帮助我,提前谢谢.
我的应用程序需要将客户当前年龄调整+0.5(如果已经过去6个月).
代码应该看起来像这样,但是6个月内会有多少个滴答?
if (DateTime.Today - dateOfBirth.Date > new TimeSpan(6))
{
adjust = 0.5M;
}
else
{
adjust = 0M;
}
Run Code Online (Sandbox Code Playgroud)
提前致谢
我已经写下了这段代码,我的程序对象是计算两个给定日期和时间之间的分钟数.让我们说分钟之间的差异:
14/1/2016 23:18
and
14/1/2004 23:18
is:
6,311,520.00 minutes
Run Code Online (Sandbox Code Playgroud)
这是我写的代码:
我在计算中有一些错误,从我发现我的问题最多是1440分钟与正确答案的差异 - 由excel检查.我认为我的问题在于计算两个日期之间的LEAP DAYS:
#include <stdio.h>
typedef struct {
int year;
int month;
int day;
int hour;
int minute;
int second;
}time;
time time1,time2;
long calcTime(time,time);
int calcDaysFromStart(int,int);
int leapcheck(int);
int main()
{
printf("Hello\n");
printf("For calculating the difference between two times:\n");
printf("Enter the date for first time:\n");
printf("Enter day:\n");
scanf("%d",&time1.day);
printf("Enter month:\n");
scanf("%d",&time1.month);
printf("Enter year:\n");
scanf("%d",&time1.year);
printf("Enter the exact hour for first time:\n");
printf("Enter the hour:\n");
scanf("%d",&time1.hour);
printf("Enter the minutes:\n"); …Run Code Online (Sandbox Code Playgroud) 我的约会声明中有错误.评论dateiff和'Nothing clicked'位工作正常.我认为它与日期变量的格式有关.
错误信息..
消息245,级别16,状态1,行2转换将varchar值'Nothing clicked'转换为数据类型int时失败.
select
case
when stVs.DateLastAction is null then 'Nothing clicked'
else DATEDIFF(MI,StVs.DateSessionStarted,stVs.DateLastAction)
end as test
From Stats_VisitorSessions StVs
Run Code Online (Sandbox Code Playgroud) 我有data.table以下几点:
ID start_date end_date
1 2015.01.01 2016.02.01
2 2015.06.01 2016.03.01
3 2016.01.01 2017.01.01
Run Code Online (Sandbox Code Playgroud)
我想得到以下内容:
ID start_date end_date Months_passed
1 2015.01.01 2016.02.01 13
2 2015.06.01 2016.03.01 9
3 2016.01.01 2017.01.01 12
Run Code Online (Sandbox Code Playgroud)
我正在尝试以下代码:
DT[, Months_passed:= length(seq(from = start_date, to = end_date, by='month')) - 1]
Run Code Online (Sandbox Code Playgroud)
但是我得到了错误
"seq.Date中的错误(from = start_date,to = end_date,by ="month"):'from'必须长度为1"
我希望在两个日期之间的数组中依次获得所有月份和年份.我希望输出像这样的格式:Ym
我做完了.但是,我只是想知道是否有任何简单的方法来获得相同的结果.
有我的代码:
public function __construct()
{
$this->params['start-date'] = date('Y-m-d', strtotime("01-01-2016"));
$this->params['end-date'] = date('Y-m-d', time());
}
/**
* @return array
*/
private function _getAllMonths()
{
$start = date_parse($this->params["start-date"]);
$end = date_parse($this->params["end-date"]);
$output[] = ['month' => $start["year"]."-0".$start["month"]];
//loop years
for($i=(int)$start["year"];$i<=(int)$end["year"];$i++)
{
//control months and start year
$k = $i == $start["year"] ? (int)$start["month"] + 1 : 1;
//loop months
for($j=$k;$j<13;$j++)
{
if($i==$end["year"] && $j==$end["month"])
break;
$output[] = ["month" => $i."-".str_pad($j, 2, "0", STR_PAD_LEFT)];
}
}
return $output;
}
Run Code Online (Sandbox Code Playgroud)
请解释我怎么样?