Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
lemodizon
- Posts: 195
- Joined: Thu Apr 05, 2018 3:33 pm
Post
by lemodizon » Sun May 26, 2024 3:10 pm
Hello everyone,
i want to set that every 10th and 25th of the month is the cut-off and it will display the remaining number of days before the cut-off.
I was able to get the numbers of day in my code unfortunately I can't figure out on how to set the 10th & 25th hope you can help me out. thanks
Code: Select all
on mouseUp
put the short date into tConvertDate
put tConvertDate into fld "CurrentDate"
put tConvertDate into tStart
convert tConvertDate to dateitems
add 15 to item 3 of tConvertDate
convert tConvertDate to short date
put tConvertDate into tEnd
put tEnd into fld "date2"
put daysBetween(tStart, tEnd) into tDays
answer information "There are " & tDays & " days between " & tStart & " and " & tEnd
end mouseUp
function daysBetween pDate1, pDate2
convert pDate1 from short date to dateitems
convert pDate2 from short date to dateitems
put 12 into item 4 of pDate1
put 12 into item 4 of pDate2
repeat with i = 5 to 7
put 0 into item i of pDate1
put 0 into item i of pDate2
end repeat
convert pDate1 from dateItems to seconds
convert pDate2 from dateItems to seconds
put abs(pDate1 - pDate2) into tDiff
return tDiff / (60 * 60 * 24)
end daysBetween
-
Attachments
-
- d1_cuurent date.png (11.57 KiB) Viewed 434 times
Thank you & God Bless Everyone
Regards,
lemodizon
-
bn
- VIP Livecode Opensource Backer
- Posts: 4036
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Post
by bn » Sun May 26, 2024 4:53 pm
Hi lemodizon,
this does what you want for 1 target day, modify it for 2
Code: Select all
on mouseUp
put the short date into tConvertDate
put tConvertDate into fld "CurrentDate"
put tConvertDate into tStart
put 15 into tDayOfMonth
convert tConvertDate to dateitems
put tConvertDate into tFirstTargetDay
if item 3 of tConvertDate > tDayOfMonth then -- we are beyond the targetDay
add 1 to item 2 of tFirstTargetDay -- go next month
put tDayOfMonth into item 3 of tFirstTargetDay -- set day in next month
else
-- we are before or at the targetDay
put tDayOfMonth into item 3 of tFirstTargetDay
end if
put 12 into item 4 of tConvertDate
put 12 into item 4 of tFirstTargetDay
convert tConvertDate from dateItems to seconds
convert tFirstTargetDay from dateItems to seconds
put tFirstTargetDay - tConvertDate into tDiff
convert tFirstTargetDay from seconds to dateItems
convert tFirstTargetDay from dateItems to short date
answer tDiff / (60 * 60 * 24) && "days until" && tFirstTargetDay
end mouseUp
The nice thing about dateItems is that you can put any number into the items and it will convert it to the correct date.
What is the date in 250 days from today:
Code: Select all
on mouseUp
put the short date into tToday
convert tToday to dateItems
add 250 to item 3 of tToday
convert tToday from dateItems to short date
answer tToday && "date 250 days from today"
end mouseUp
Kind regards
Bernd
-
lemodizon
- Posts: 195
- Joined: Thu Apr 05, 2018 3:33 pm
Post
by lemodizon » Mon May 27, 2024 10:45 am
Hi Bernd,
Thanks for helping me out. This is my first time to use the date and time in livecode kinda little bit confuse in converting.
I tried your code it works. but when i tried to put the cut-off days i noticed if i adjusted the date manually for example if the current date is 6/9/24 it will prompt 1 day until 6/10/24 (this is the cut-off) this is the display i got.
- cut-off.png (5.44 KiB) Viewed 363 times
kindly check my codes if missed something coz i'm trying to put the 2 cut-off dates every 10th and 25th
Code: Select all
on mouseUp
put the short date into tConvertDate
put tConvertDate into fld "CurrentDate"
put tConvertDate into tStart
put 10 into tDayOfMonth10
put 25 into tDayOfMonth25
convert tConvertDate to dateitems
put tConvertDate into tFirstTargetDay
put tConvertDate into tSecondTargetDay
if item 3 of tConvertDate > tFirstTargetDay then -- we are beyond the targetDay
add 1 to item 2 of tFirstTargetDay -- go next month
put tDayOfMonth10 into item 3 of tFirstTargetDay -- set day in next month
else if item 3 of tConvertDate < tDayOfMonth25 or item 3 of tConvertDate > tDayOfMonth25 then
-- we are before or at the targetDay
put tDayOfMonth25 into item 3 of tSecondTargetDay
put 12 into item 4 of tConvertDate
put 12 into item 4 of tSecondTargetDay
convert tConvertDate from dateItems to seconds
convert tSecondTargetDay from dateItems to seconds
put tSecondTargetDay - tConvertDate into tDiff
convert tSecondTargetDay from seconds to dateItems
convert tSecondTargetDay from dateItems to short date
answer tDiff / (60 * 60 * 24) && "days until" && tSecondTargetDay
end if
put 12 into item 4 of tConvertDate
put 12 into item 4 of tFirstTargetDay
convert tConvertDate from dateItems to seconds
convert tFirstTargetDay from dateItems to seconds
put tFirstTargetDay - tConvertDate into tDiff
convert tFirstTargetDay from seconds to dateItems
convert tFirstTargetDay from dateItems to short date
answer tDiff / (60 * 60 * 24) && "days until" && tFirstTargetDay
end mouseUp
Thanks Bernd
Thank you & God Bless Everyone
Regards,
lemodizon
-
bn
- VIP Livecode Opensource Backer
- Posts: 4036
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Post
by bn » Mon May 27, 2024 12:32 pm
Hi Lemondizon,
I changed the script to make it a bit clearer and it calculates the days to the next 10th and 25th of month from today. I assume you want both results.
It should be easier now to adapt the script if needed.
Code: Select all
on mouseUp
put the short date into tConvertDate
put tConvertDate into fld "CurrentDate"
put tConvertDate into tStart
put 10 into tDayOfMonth10
put 25 into tDayOfMonth25
convert tConvertDate to dateitems
put tConvertDate into tFirstTargetDay
put tConvertDate into tSecondTargetDay
## first test tDayOfMonth10
if item 3 of tConvertDate > tDayOfMonth10 then -- we are beyond tDayOfMonth10
add 1 to item 2 of tFirstTargetDay -- go next month
put tDayOfMonth10 into item 3 of tFirstTargetDay -- set day in next month
else
put tDayOfMonth10 into item 3 of tFirstTargetDay -- set day in this month
end if
put 12 into item 4 of tConvertDate
put 12 into item 4 of tFirstTargetDay
convert tConvertDate from dateItems to seconds
convert tFirstTargetDay from dateItems to seconds
put tFirstTargetDay - tConvertDate into tDiffFirstTargetDay
put tDiffFirstTargetDay / (60 * 60 * 24) into tDaysToFirstTarget
## end test tDaysOfMonth10
## now test tDayOfMonth25
-- restore tConvertDate to today as short date
put tStart into tConvertDate
convert tConvertDate to dateItems
If item 3 of tConvertDate > tDayOfMonth25 then -- we are beyond tDayOfMonth25
add 1 to item 2 of tSecondTargetDay -- go next month
put tDayOfMonth25 into item 3 of tSecondTargetDay -- set day in next month
else
put tDayOfMonth25 into item 3 of tSecondTargetDay -- set day in this month
end if
put 12 into item 4 of tConvertDate
put 12 into item 4 of tSecondTargetDay
convert tConvertDate from dateItems to seconds
convert tSecondTargetDay from dateItems to seconds
put tSecondTargetDay - tConvertDate into tDiffSecondTargetDay
put tDiffSecondTargetDay / (60 * 60 * 24) into tDaysToSecondTarget
## end test tDayOfMonth25
answer "Days to 10th " && tDaysToFirstTarget & cr & "Days to 25th " && tDaysToSecondTarget
end mouseUp
Kind regards
Bernd
-
lemodizon
- Posts: 195
- Joined: Thu Apr 05, 2018 3:33 pm
Post
by lemodizon » Mon May 27, 2024 1:16 pm
bn wrote: ↑Mon May 27, 2024 12:32 pm
Hi Lemondizon,
I changed the script to make it a bit clearer and it calculates the days to the next 10th and 25th of month from today. I assume you want both results.
It should be easier now to adapt the script if needed.
Code: Select all
on mouseUp
put the short date into tConvertDate
put tConvertDate into fld "CurrentDate"
put tConvertDate into tStart
put 10 into tDayOfMonth10
put 25 into tDayOfMonth25
convert tConvertDate to dateitems
put tConvertDate into tFirstTargetDay
put tConvertDate into tSecondTargetDay
## first test tDayOfMonth10
if item 3 of tConvertDate > tDayOfMonth10 then -- we are beyond tDayOfMonth10
add 1 to item 2 of tFirstTargetDay -- go next month
put tDayOfMonth10 into item 3 of tFirstTargetDay -- set day in next month
else
put tDayOfMonth10 into item 3 of tFirstTargetDay -- set day in this month
end if
put 12 into item 4 of tConvertDate
put 12 into item 4 of tFirstTargetDay
convert tConvertDate from dateItems to seconds
convert tFirstTargetDay from dateItems to seconds
put tFirstTargetDay - tConvertDate into tDiffFirstTargetDay
put tDiffFirstTargetDay / (60 * 60 * 24) into tDaysToFirstTarget
## end test tDaysOfMonth10
## now test tDayOfMonth25
-- restore tConvertDate to today as short date
put tStart into tConvertDate
convert tConvertDate to dateItems
If item 3 of tConvertDate > tDayOfMonth25 then -- we are beyond tDayOfMonth25
add 1 to item 2 of tSecondTargetDay -- go next month
put tDayOfMonth25 into item 3 of tSecondTargetDay -- set day in next month
else
put tDayOfMonth25 into item 3 of tSecondTargetDay -- set day in this month
end if
put 12 into item 4 of tConvertDate
put 12 into item 4 of tSecondTargetDay
convert tConvertDate from dateItems to seconds
convert tSecondTargetDay from dateItems to seconds
put tSecondTargetDay - tConvertDate into tDiffSecondTargetDay
put tDiffSecondTargetDay / (60 * 60 * 24) into tDaysToSecondTarget
## end test tDayOfMonth25
answer "Days to 10th " && tDaysToFirstTarget & cr & "Days to 25th " && tDaysToSecondTarget
end mouseUp
Kind regards
Bernd
Hi Bernd,
Thank you so much. your code will help me more understand time and date in livecode
thank you for helping me I appreciate it.
Thank you & God Bless Everyone
Regards,
lemodizon