I'm trying to find how many days between a date and today.
I'm able to get the correct number of days but it show as negative.
Integer(DateDiff("day",Date(DateTimeNow()),Date([LAST_RECORD_DT])))
I would like the same result but positive number.
Your answer in your comment is good, but this is better in my opinion:
If LAST_RECORD_DT is in the past (which seems to be the case for you):
Integer(DateDiff("day",Date([LAST_RECORD_DT]),Date(DateTimeNow())))
If LAST_RECORD_DT is in the future:
Integer(DateDiff("day",Date(DateTimeNow()),Date([LAST_RECORD_DT])))
If you want it to always be positive, you can use Abs:
Abs(Integer(DateDiff("day",Date([LAST_RECORD_DT]),Date(DateTimeNow()))))
Related
I am currently trying to setup my own holiday iCalendar to which I can subscribe on, since I don't want to depend on 3rd party services.
I am currently trying to make the the VEVENTs for Christmas. The 2nd, 3rd and 4th advent, as well as the Christmas holidays are straight forward, however I have big issues to model the 1st advent.
Specifically, the problem is that the first advent can be in November and December (27th November to 3rd Devember)
How can I make a recurring event (or, more specifically, the RRULE) to cover all cases for the 1st advent?
What I've tried
My first idea was this:
FREQ=YEARLY;INTERVAL=1;BYMONTH=11,12;BYMONTHDAY=27,28,29,30,1,2,3;BYDAY=SU
The idea was to just pick the one Sunday in between 27th November and 3rd December. This does of course not work because BYMONTH expands the search to all days in November and December, and BYMONTHDAY limits the search to those days in both months. I.e. November 1st, November 2nd, ... December 27th, December 28th, ..., which is of course not what I want.
Next, I tried to use BYYEARDAY=331,332,333,334,335,336,337 instead of BYMONTHDAY and BYMONTH, but unfortunately my webdav server (Nextcloud, which uses Sabre as far as I know. I got an error message "Invalid BYYEARDAY rule") does not support this.
My next idea was to use multiple RRULEs -- at least I did not see any passage in the RFC stating that only one RRULE is allowed at most. So I ended up with:
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=SU;BYMONTHDAY=27,28,29,30;BYMONTH=11
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=SU;BYMONTHDAY=1,2,3;BYMONTH=12
Didn't work as well. My last resort was to create two separate VEVENTs, one with the first RRULE above and one with the second RRULE above, but otherwise identical. This worked, but it left me confused.
Is there no better solution? How would you do it?
unfortunately my webdav server (Nextcloud, which uses Sabre as far as I know. I got an error message "Invalid BYYEARDAY rule") does not support this.
Well I think you should raise a bug report, because as far I can tell your solutions are correct and RFC-compliant.
I tried your solutions 2 and 3 with different libs (my own lib php-rrule, and rrule.js) and both options seems to work just fine.
FREQ=YEARLY;BYDAY=SU;BYYEARDAY=331,332,333,334,335,336,337
or combining 2
FREQ=YEARLY;INTERVAL=1;BYDAY=SU;BYMONTHDAY=27,28,29,30;BYMONTH=11
FREQ=YEARLY;INTERVAL=1;BYDAY=SU;BYMONTHDAY=1,2,3;BYMONTH=12
will both produce:
2018-12-02
2019-12-01
2020-11-29
2021-11-28
2022-11-27
2023-12-03
2024-12-01
2025-11-30
2026-11-29
2027-11-28
which according to Google and Wikipedia are the correct dates for the 1st Advent Sunday in the next 10 years.
Side note
at least I did not see any passage in the RFC stating that only one RRULE is allowed at most.
While not strictly forbidden, in RFC 5545 it's literally written everytime RRULE is mentioned:
;
; The following is OPTIONAL,
; but SHOULD NOT occur more than once.
;
rrule
Appendix A even states in the "New restrictions":
2. The "RRULE" property SHOULD NOT occur more than once in a
component.
That being said, multiple RRULE is a great feature, I don't know why they restricted it.
If I'm not mistaken, the first Advent is always the fifth last Sunday in a year. So the following rule should do the trick:
FREQ=YEARLY;BYDAY=-5SU
See the next 10 results: http://recurrence-expansion-service.appspot.com/reaas?dtstart=20181202&rrule=FREQ%3DYEARLY%3BBYDAY%3D-5SU&max_instances=10
Or to put it another way:
FREQ=YEARLY;BYDAY=SU;BYSETPOS=-5
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)
I have an array with strings of dates. The format is "2/27/16 3:47" so "m-d-y H:M". However, DateTime parses this as 0016-27-02T03:47:00. I would like to have the output be: 2016-27-2T03:47:00.
My code is:
map(date-> DateTime(date, "mm/dd/yy HH:MM"), datsub[:date])
Side question: The output type becomes Any. Is this the correct type or should it be DateTime or something similar?
As #akrun mentioned, you should add the year yourself:
Dates.Year(2000) + DateTime(date, "m/d/y H:M")
This is more explicit about exactly what is happening. Otherwise Dates would have to guess what exactly something like 97 means: 1997 or 2097, or actually year [00]97?
It's possible that you might want to come up with a reasonable cutoff for what year to add. You can try the following:
expandyear(date::DateTime) = date + (Dates.year(date) < 25 ? Dates.Year(2000) : Dates.Year(1900))
with whatever cutoff you think makes sense.
The issue with return types with map is a known problem that has been fixed in the latest v0.5 nightlies. Julia v0.5 is likely to be released in the near future, perhaps within several months.
I am trying to calculate the amount of days between two dates but my formula doesn't seem to be working properly. It's as is the function is ignoring the years in the dates. My function is as follows:
=IF([Today's date]>[Expiration Date],-DATEDIF([Expiration Date],[Today's date],"d"),(DATEDIF([Today's date],[Expiration Date],"d")))
I receive this error if I use the above function(Owners removed):
But then I replace -DATEDIF([Expiration Date],[Today's date],"d") with -DATEDIF([Today's date],[Expiration Date]"d") i get this result:
This is telling me that both cases are being treated as IF([Today's date]>[Expiration Date] even though 3/24/2015 is clearly larger than 11/03/2014. Can somebody please tell me what I'm doing wrong? Thanks.
=[ExpirationDate] - [TodaysDate]
Hey, been looking for a while but I can't seem to find any info on how to handle date in classic asp.
For now, I need a way to calculate the number of days passed in the current year. I was thinking about a simple function that would take the current date, then make another date with (day = 1, month = 1, year(now)). And finally get the datediff(day) for these two. Easy enough, but I can't figure out how to do this. Help is appreciated!
Perhaps this example can help you? https://web.archive.org/web/20211020135923/https://www.4guysfromrolla.com/webtech/110398-1.shtml
DateDiff("d",DateSerial(Year(Now),1,1),Date)