Calculate an older date in Freemarker - date

I need to create a calendar control for selecting Date of Birth. My custom calendar control has fields for setting minDate and maxDate that can be used to set the range of dates that can be selected.
I can get the present date into a variable and use it as maxDate as below.
<#assign dateObject=.now/>
<#assign todaysDate=dateObject?date/>
How can I calculate a date around 100 years prior in a similar way? I read through the official documentation and could not find any operation that could do this.

You aren't meant to calculate such things in the MVC View... the date range to display should come from the data-model. Anyway, you will need GregorianCalendar arithmetic for this, and FreeMarker has no such thing built into. But you can write a Java method to do that and then just call that from the template.
BTW, the naive way of doing this is (.now?long - 1000 * 60 * 60 * 24 * daysBefore)?numberToDate. The problem with this is that you can have a duplicate or skipped day if .now is near midnight, and some days in the range hit a daylight saving change.

Related

Quicksight datepicker for month only

I'm searching for a way to have month selection and that will serve as startdate and enddate for the date filtering.
I'm building a monthly report on quicksight, I try to use the last 31 days but that give information of multiple months
I already create date picker for those parameters but didn't find any way to limit the value to be the complete month only.
Example : if select the 12 september I desire to get the September values only (from the 1er to the 31th)
Any advice is welcome
Thanks for your help
First, add a new date filter (if you want, e.g., today to be the default you'll need to add a dynamic default against a data set that returns today)
Add a new control (I found naming this to be difficult, perhaps you're better at picking names than I am)
Add a new calculated field that returns 1 if the truncDate of your date field and the truncDate of your parameter are equal, otherwise return 0
ifelse(
truncDate("MM", {date}) = truncDate("MM", ${InMonth}),
1,
0
)
Finally, add a filter that checks where your calculated field is 1 and apply it to all visuals

How can I make a database structure in mongodb for saving the date range?

Here I'm saving the date range using golang. Suppose we have to save the all monday comes between the range of the 1-may-2018 to 14-july-2018.
How we will find all the monday between these range using golang and on the other hand we have set the start_time (8:00 A.M.) and the end_time (6:00 P.M.) of the first two coming monday in the database but on the third monday we have a change in the schedule that there is a time change like start_time (9:00 A.M.) and end_time (5:00 P.M.). Then how I will make my database to make this situation in practically using the golang.
Can Anybody help me for this to solve this solution. I made a database for and I do ppr work on it and make some fields shown below:-
Fields for Schedule //Schedule is a collection name
Id (int)
Day (string)
Start_hours (int)
Start_minutes (int)
End_hours (int)
End_minutes (int)
Start_date (timestamp)
End_date (timestamp)
How I will select monday between the selected range and how will I do the situation I explained above can anybody give guidance to me to make this situation easier. Thank you if this is a basic question then I'm really sorry.
I'd make something like this.
Find the first Monday date from the date range (see for example How do I get the first Monday of a given month in Go?
Mondays happen every week, so you can easily find the rest of dates by adding 7 days till the end date
Store all the Monday dates you found with the start and end times
I wouldn't bother with hours and minutes as you can easily get them from the timestamps in Go. Here is the simplified DB structure I would make
Fields for Schedule //Schedule is a collection name
Id (int)
Day (string)
Date (timestamp) // the actual date
Start (timestamp)
End (timestamp)
You don't need any more fields. You can get the day of the week (Day (string) in your structure, e.g. Monday) from the Date field too, but I believe if you want to query the collection by different days, this might speed things up, but be careful if you need to adjust for time zones. If you work with more than one, then store everything in UTC and you may have an extra filed Timezone, cos a date could be Monday for one zone and Sunday for another.
So, the Schedule will hold weekdays and start and end times for each of them. I'm not sure if you need to store initial date ranges, the Schedule collection will hold that range as well, form the first record to the last one. In my mind, I'd initially populate the collection with a given date range, then later on, I can modify it by adding new days, or deleting them.
When you query this collection with some start and end date range for the Date field, if your first result comes newer than 7 days from the start, this means you miss 1 or more entries from the start. If the last result comes older than 7 days from the range end, this means you miss some entries prior to the range end.
There is nothing specific to Go, in my opinion, Go works well with dates and you don't need any special date structures in your DB.

How can I Add Days to a date property in Cypher?

I have been working on a readmission issue using a clinical graph dataset. Let's say a patient is being readmitted within 30 days. So, this means I need add 30 days to the first date (visit date) for the second visit date.
Here is the Cypher query:
MATCH(p:Person)-[r:PATIENT_HAS]->(e:Encounter)
WITH p,e
MATCH (p)-[r:PATIENT_HAS]-(e2:Encounter) WHERE e2.ADMIT_DATE < (e.ADMIT_DATE + 30)
This query won't work because the date property is in YYYYMMDD format. For example, if it is 20151225, it will give 20151255. But I need to get it as 20160124 after adding 30 days. Is there any other way to use a different format than YYYYMMDD. I know that there is string format as YYYY-MM-DD, but what is the way to use this format for adding days?
How can accomplish this?
I would appreciate your help.
The best way to deal with dates in Neo4j in my opinion is to have them saved as UNIX epoch time in miliseconds or seconds. We have a great plugin in Neo4j called apoc procedures that allows you to use awesome procedures. In your specific case I would utilize apoc.date.*procedures and parse your date format to epoch time in seconds.
MATCH (e:Encounter)
WITH e,apoc.date.parse(e.ADMIT_DATE,"s","YYYYMMDD") as unix
set e.unix = unix
So now your query would look like :
MATCH(p:Person)-[r:PATIENT_HAS]->(e:Encounter)
MATCH (p)-[r:PATIENT_HAS]-(e2:Encounter)
WHERE e2.unix < e.unix + (30 * 24 * 60 * 60)
Ofcourse you can simplify this query and make it shorter:
MATCH (e2:Encounter)-[r:PATIENT_HAS]-(p:Person)-[r:PATIENT_HAS]->(e:Encounter)
WHERE e2.unix < e.unix + (30 * 24 * 60 * 60)
You can construct a Duration, and add it directly to a date.
Here is an example in Cypher:
RETURN Date() + Duration({days: 30})
Reference: https://neo4j.com/docs/cypher-manual/current/functions/temporal/duration/
I'm currently using Neo4j 4.0.3 and the following works:
RETURN REPLACE(toString(date('20151225') + duration('P30D')),'-','')
// "20160124"
We found out a temporary solution: We are setting a specific date in the past (1/1/2009 in our case), and are getting the difference between the first visit (e.ADMIT_DATE-1/1/2009) and the second visit (e2.ADMIT_DATE-1/1/2009) as days. Then we are able to get the difference between the first and second visits (e2.DAYS-e.DAYS) to figure out 30 days for the readmission criteria.
I had checked out the apoc procedures plugin and it seemed a bit complicated. But I can definitely retry it. Many thanks for your great responses folks.

Grouping Expert, Current date against start date

I am having trouble grouping certain results in a work in progress report that arranges by start date, I have grouped using fixed values before but because the dates keep moving I am unsure what to do.
The start date is WIP_Schedule.Start_Date
the groups I am trying to create are:
[Group1] Overdue = the current date has passed the start date.
[Group2] (Yet to be named) = the current date 2 week period prior to the start date
[Group3] To Do = the current date after the two week period prior to the start date.
I am after a works instruction on how to achieve this.
I know this isn't a lot of information, if you require any more please ask.
Thanks,
Daniel
This is a pretty straightforward requirement, so you should be able to figure it out by searching the web. However, I'll give you part of the answer and hopefully you can figure it out.
Start by creating a formula to figure out the status of the date.
If {WIP_Schedule.Start_Date} > current date then "Overdue"
Else......
Then you can group based on that formula. All you have to do is figure out the rest of the formula.

Number of days between past date and current date in Google spreadsheet

I want to calculate the number of days passed between past date and a current date. My past date is in the format dd/mm/yyyy format. I have used below mentioned formulas but giving the proper output.
=DAYS360(A2,TODAY())
=MINUS(D2,TODAY())
In the above formula A2 = 4/12/2012 (dd/mm/yyyy) and I am not sure whether TODAY returns in dd/mm/yyyy format or not. I have tried using 123 button on the tool bar, but no luck.
The following seemed to work well for me:
=DATEDIF(B2, Today(), "D")
DAYS360 does not calculate what you want, i.e. the number of days passed between the two dates – see the end of this post for details.
MINUS() should work fine, just not how you tried but the other way round:
=MINUS(TODAY(),D2)
You may also use simple subtraction (-):
=TODAY()-D2
I made an updated copy of #DrCord’s sample spreadsheet to illustrate this.
Are you SURE you want DAYS360? That is a specialized function used in the
financial sector to simplify calculations for bonds. It assumes a 360 day
year, with 12 months of 30 days each. If you really want actual days, you'll
lose 6 days each year.
[source]
Since this is the top Google answer for this, and it was way easier than I expected, here is the simple answer. Just subtract date1 from date2.
If this is your spreadsheet dates
A B
1 10/11/2017 12/1/2017
=(B1)-(A1)
results in 51, which is the number of days between a past date and a current date in Google spreadsheet
As long as it is a date format Google Sheets recognizes, you can directly subtract them and it will be correct.
To do it for a current date, just use the =TODAY() function.
=TODAY()-A1
While today works great, you can't use a date directly in the formula, you should referencing a cell that contains a date.
=(12/1/2017)-(10/1/2017) results in 0.0009915716411, not 61.
I used your idea, and found the difference and then just divided by 365 days. Worked a treat.
=MINUS(F2,TODAY())/365
Then I shifted my cell properties to not display decimals.
If you are using the two formulas at the same time, it will not work...
Here is a simple spreadsheet with it working:
https://docs.google.com/spreadsheet/ccc?key=0AiOy0YDBXjt4dDJSQWg1Qlp6TEw5SzNqZENGOWgwbGc
If you are still getting problems I would need to know what type of erroneous result you are getting.
Today() returns a numeric integer value: Returns the current computer system date. The value is updated when your document recalculates. TODAY is a function without arguments.
The following worked for me. Kindly note that TODAY() must NOT be the first argument in the function otherwise it will not work.
=DATEDIF( W2, TODAY(), "d")
Today() does return value in DATE format.
Select your "Days left field" and paste this formula in the field
=DAYS360(today(),C2)
Go to Format > Number > More formats >Custom number format and select the number with no decimal numbers.
I tested, it works, at least in new version of Sheets, March 2015.