get difference in minutes in xslt 2.0 minutes-from-duration - date

i have to dates: xs:date(current-date()) and something like this 2017-11-01T09:17:00Z.
I need to get difference in minutes.
My idea is with minutes-from-duration() function, but i don't know how convert the dates to right input

You can simply substract two dates or dateTimes in XSLT/XPath 2 or later with e.g. current-dateTime() - xs:dateTime('2017-11-01T09:17:00Z') to get a duration, then you can use your function or other operations like e.g. (current-dateTime() - xs:dateTime('2017-11-01T09:17:00Z')) div xs:dayTimeDuration('PT1M') which would divide the duration by 1min.

Related

kdb+/q:How does one convert a utc timestamp to a datetime?

How could one convert the following timestamp t:1595779091979 into its equivalent `datetime$() representation (UTC)?
For instance if one tries to do so using the following.
q) `datetime$t
0000.00.00T00:00:00.000
q) `timestamp$t
2000.01.01D00:26:35.779091979
(Both are incorrect, the time should be 2020.07.26D...)
Thanks
The timestamp 1595779091979 looks like milliseconds since 1970 epoch. If you drop the millis - the conversion is simply
q)1970.01.01+0D00:00:01*1595779091
2020.07.26D15:58:11.000000000
or keeping the millis:
q)1970.01.01+0D00:00:00.001*1595779091979
2020.07.26D15:58:11.979000000
Finally, you can add the following definition to your utility library
ts:1970.01.01+0D00:00:00.001*
and use it in your code whenever you need conversion
q)ts 1595779091979
2020.07.26D15:58:11.979000000
Update: A slightly shorter solution can be written as
ts:1970.01.01D+1000000*

spss-modeler date difference getting negative results

First of all, I'm new to SPSS modeler, sorry if my question sound too obvious for experts, but what I'm trying is to calculate the date difference between two date values ( arrive_Date , Depart_Date ) in (Hours), I used this function time_hours_difference , this function works okay if the Arrive_Date and depart_date are the same day, but if the days are different, the date difference is in negative value, I searched and enabled this option: Rollover days/mins in stream properties, but the problem remains the same.
I hope you can help me with this beginner question.
Thanks
Hope its not too late. You are getting negative values because time_hours_difference extract only the time from the two specified timestamps and computes the difference out of it. It doesn't take the date values into account.
For example:
time_hours_difference('2012-08-02 14:10:50,2012-08-05 13:36:26)
Output:
-0.573
Remember, here time_in_hours('0130') under time format 'HHMM' evaluates to 1.5.
Here is my solution: in order to take days into account, first extract date_days_difference and multiply it with 24 to bring it in Hours and then sum it up with the time difference using time_hours_difference.
date_days_difference(arrive_Date,Depart_Date)*24 +
time_hours_difference(arrive_Date,(to_string(datetime_date(arrive_Date)) >< " 23:59:00")) +
time_hours_difference((to_string(datetime_date(Depart_Date)) >< " 00:00:00"),Depart_Date)

Create date from day, month, year as integers in KDB Q

I am trying to get a date from its integer components: I have day, month and year as variables (that can change, I don't want to hard code them), and I want to reunite them in a date variable.
For example, something like that;
myDay: 15
myMonth: 4
myYear: 2016
`date$(myYear,myMonth,myDay) --> should return 2016.4.15 (formatted as a date).
Any way to do that?
Thank you
q)d:3
q)m:8
q)y:2016
q)"D"$"." sv string (y;m;d)
2016.08.03
See cast vs tok - need to use different arguments depending on if what you're casting from is a string or not

How can I add several months to a date coming from a date form field?

With DateJS, you'd add e.g. six months to the current date like this:
Date.today().addMonths(6);
However, I need to add 24 months not to today's date, but to a date which a user has typed into a date field. So the today() should in principle be replaced by something like this.getField('begin_date').value.
The result shall be written into another data form field.
I tried hard, but couldn't make it. Can anyone help me out?
Providing the input value is a textual representation of a date, you need to convert it into a Date object at the first place. Then you can work with it as you want.
DateJS has a pretty smart parse() function which does exactly that, so you'd achieve it like this:
Date.parse(this.getField('begin_date').value).addMonths(24)
When a specific date format is needed, like DD.MM.YYYY commonly used in Europe, you can use parseExact() and specify the format. Like this:
Date.parseExact(dateToParse, 'dd.MM.yyyy') // leading zeroes required; parses 01.04.2014 but not 1.4.2014
Date.parseExact(dateToParse, 'd.M.yyyy') // leading zeroes not required; parses both 01.04.2014 and 1.4.2014
Here is a solution that I found for my problem, using DateJS as well:
start = this.getField('begin_date').value;
var d1 = util.scand("dd.mm.yyyy", start);
var myDate = new Date(d1);
result = myDate.addMonths(24);
This works pretty fine, also spanning leap years, except for the 28th of February, 2014/2018/2022 ... ; the result then will be the 28th of February, 2016/2020/2024 ... and not the 29th of February 2016/2020/2024... In these cases it's up to the user to accept the 28th or to manually change the date to the 29th.

zend_date relative time

i want to make stackoverflow timestamps(X minutes ago, etc). How i can make it using zend_date? I found How to calculate time passed with PHP or Zend_Date? this realisation, but it uses other library. Are there any different ways?
How about Zend_Date::subDate()?
$d1 = new Zend_Date();
$d2 = new Zend_Date($old_date);
$diff = $d1->subDate($d2);
After you've got the difference, you can check out one of these helpers:
Relative time view helper
Zend_View_Helper_Relativetime
Even if you don't want the whole Zym framework, you could still add their TimeSince view helper to your own application.
You can subtract timestamps of two dates to find difference between them in seconds and then use division and modulo to represent it as minutes, days etc.