- Posts: 409
- Thank you received: 34
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
SOLVED: Calculate a date 5 day in the future
- blocka
- Topic Author
- Offline
- Platinum Member
Less
More
3 years 8 months ago #201995
by blocka
Calculate a date 5 day in the future was created by blocka
I need to save a date that is the is a sum of the current date plus 5 days. This will allow me to display a deadline to the participant like:
Today's day is 2020-06-29: You need to mail in your sample by 2020-07-04.
That is, I want to calculate today's date + 5 days.
Can anyone suggest how this can be done?
Today's day is 2020-06-29: You need to mail in your sample by 2020-07-04.
That is, I want to calculate today's date + 5 days.
Can anyone suggest how this can be done?
The topic has been locked.
- blocka
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 409
- Thank you received: 34
3 years 8 months ago #201996
by blocka
Replied by blocka on topic SOLVED: Calculate a date 5 day in the future
Figured it out, for others:
{( date('d F Y',((strtotime(date('Y-m-d')) + (60 * 60 * 24 * 5) ))) )}
Where the 60 * 60 * 24 is number of seconds in a day, and 5 is the number of days.
{( date('d F Y',((strtotime(date('Y-m-d')) + (60 * 60 * 24 * 5) ))) )}
Where the 60 * 60 * 24 is number of seconds in a day, and 5 is the number of days.
The following user(s) said Thank You: holch
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13935
- Thank you received: 2551
3 years 8 months ago #202017
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic SOLVED: Calculate a date 5 day in the future
Or : strtotime("+5 days")
www.php.net/manual/en/function.strtotime.php#example-2873
www.php.net/manual/en/function.strtotime.php#example-2873
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
- lindalimesurvey
- Offline
- New Member
Less
More
- Posts: 1
- Thank you received: 0
3 years 3 months ago #208880
by lindalimesurvey
Replied by lindalimesurvey on topic SOLVED: Calculate a date 5 day in the future
Is it also possible to do this calculation, not with a current date, but with a date the user has entered? So the user entered 01-01-2020 and I want to add x-days to this (the days are also a variable and not a fixed value in this case)
I would be really thankful for any help!
I would be really thankful for any help!
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12789
- Thank you received: 3940
3 years 3 months ago - 3 years 3 months ago #208886
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic SOLVED: Calculate a date 5 day in the future
Hi, you may use this equation:
Q1: the question where the date is entered.
Q1a: the question where the added days are entered
{date('Y-m-d',mktime(0,0,0,substr(Q1,5,2),sum(substr(Q1,8,2),Q1a),substr(Q1,0,4)))}
Explanation:
The date in Q1 has a format YYYY-MM-DD; this is the format the database stores a date.
mktime is a function to create a UNIX timestamp for a date and takes the parameters
mktime(hour , minute , second , month , day , year)
We neclect the time, but then we take the substring of the date from index 5 and 2 characters long (this is the month)
Then we take the substring of the date from index 8 and 2 characters long (this is the day)
At last we take the substring of the date from index 0 and 4 characters long (this is the year)
You also see the sum
{date('Y-m-d',mktime(0,0,0,substr(Q1,5,2),sum(substr(Q1,8,2),Q1a),substr(Q1,0,4)))}
Here we add the value of question Q1a to the day parameter.
{date('Y-m-d',mktime(0,0,0,substr(Q1,5,2),sum(substr(Q1,8,2),Q1a),substr(Q1,0,4)))}
And at last we recalculate to a date with the "date" function.
This function has two parameters, the date format and the timestamp.
All these functions are explained here
manual.limesurvey.org/ExpressionScript_-...mplemented_functions
Examples with two different date formats.
To do calculations you should always use "Y-m-d".
and
Joffm
Q1: the question where the date is entered.
Q1a: the question where the added days are entered
{date('Y-m-d',mktime(0,0,0,substr(Q1,5,2),sum(substr(Q1,8,2),Q1a),substr(Q1,0,4)))}
Explanation:
The date in Q1 has a format YYYY-MM-DD; this is the format the database stores a date.
mktime is a function to create a UNIX timestamp for a date and takes the parameters
mktime(hour , minute , second , month , day , year)
We neclect the time, but then we take the substring of the date from index 5 and 2 characters long (this is the month)
Then we take the substring of the date from index 8 and 2 characters long (this is the day)
At last we take the substring of the date from index 0 and 4 characters long (this is the year)
You also see the sum
{date('Y-m-d',mktime(0,0,0,substr(Q1,5,2),sum(substr(Q1,8,2),Q1a),substr(Q1,0,4)))}
Here we add the value of question Q1a to the day parameter.
{date('Y-m-d',mktime(0,0,0,substr(Q1,5,2),sum(substr(Q1,8,2),Q1a),substr(Q1,0,4)))}
And at last we recalculate to a date with the "date" function.
This function has two parameters, the date format and the timestamp.
All these functions are explained here
manual.limesurvey.org/ExpressionScript_-...mplemented_functions
Examples with two different date formats.
To do calculations you should always use "Y-m-d".
and
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 3 months ago by Joffm.
The following user(s) said Thank You: lindalimesurvey
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13935
- Thank you received: 2551
3 years 3 months ago - 3 years 3 months ago #208892
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic SOLVED: Calculate a date 5 day in the future
I check (in 3.25) : in a second page (another group)
The date + 5 days : {date('Y-m-d',strtotime(Date.NAOK+" +5 days"))}
is OK with dd/mm/yyy or dd.mm.yyy
Same page (same question or same group) it broke.
The date + 5 days : {date('Y-m-d',strtotime(Date.NAOK+" +5 days"))}
is OK with dd/mm/yyy or dd.mm.yyy
Same page (same question or same group) it broke.
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 3 years 3 months ago by DenisChenu.
The following user(s) said Thank You: Joffm
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12789
- Thank you received: 3940
3 years 3 months ago #208895
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic SOLVED: Calculate a date 5 day in the future
And you may enter days dynamically
{date('Y-m-d',strtotime(Q1.NAOK+" +"+Q1a.NAOK+" days"))}
But - as Denis said - only on a next page.
Joffm
{date('Y-m-d',strtotime(Q1.NAOK+" +"+Q1a.NAOK+" days"))}
But - as Denis said - only on a next page.
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.