Welcome! Log In Create A New Profile

Advanced

How to determine a next date in a form window How to determine a next date in a form window then calculates days left to the next date in a table

Posted by Kobus 
Hi

Hope someone can help me with this.

How to determine a next date in a form window then calculates days left to the next date in a table.

For example in the form window
NextPTODate = CurrentPTODate + 180 //180 equals days

Then I want to calculate the days left to reach the NextPTODate in a table

For example

DaysLeft = NextPTODate - Today()

Thank you
NextPTODate is date
NextPTODate=CurrentPTODate
NextPTODate..days +=180

NextPTODate contains the date you are lookinf for now.

and for the second part, use datedifference function

In a case like that, it is VERY simple to find all these answers in the help... Just look for the keyword date and you will find the date variables and the date functions
Hi Argus

Thanks for replying.

I enter the code

EDT_NextPTODate is Date
EDT_NextPTODate = EDT_PTODDate
EDT_NextPTODate..days += 180

and getting an error on line 3 saying "Bad Date". The "day" turns red.
You must use ..day not ..days

Check the sintax in the help: [doc.windev.com]

Regards

Paulo Oliveira
Hi Pao

I did change it to Day as describe in the Help but I still get the same error "Bad Date" line 3

EDT_NextPTODate is Date
EDT_NextPTODate = EDT_PTODDate
EDT_NextPTODate..day += 180

I had a look again at the help again and realize that my date format is "dd/mm/yyyy" and the reason for the "Bad Date" is because it only work when it is in the date format "yyyy/mm/dd". After I changed it to the the correct date format there was no errors but it does not add 180 days to the NextPTODate as requested. It add about 60 days only. When I enter a new record it doesn't display the NextPTODate at all.

When I look at the help it shows me the following

// Add 5 days to the date
StartDate.Day += 5

where between "StartdDate" and "Day" is only one point. When I change my code to this I receive an error. Is this for a newer version of WinDev. I'm currently using WinDev 23.

Regards
Hi Pao

If I add the code

Info(EDT_NextPTODate)

a popup window shows the correct date but how do I save it in the EDT_NextPTODate field. I need it to be saved and not in a popup window.
If Info(EDT_NextPTODate) returns the expected value i don't understant what you need more.

Regards

Paulo Oliveira
if I understand correctly the problem (and that is a big IF, as you are not giving us much to work with), you currently do not understand the format settings of fields

In and edit field, there are TWO formats

The first one is the DISPLAY format, in your case it's "dd/mm/yyyy"
The second one is the RETURN or INTERNAL format and for a date it should in nearly ALL cases be YYYYMMDD

If you set up your fields like that, you can do MyDateInVariable = MyDateInField and MyDateInField=MyDateInVar without any problem because they are all using the same YYYYMMDD

And you choose whatever you want to DISPLAY
Hello Kobus

When I have to do date arithmetic I use the DatetoInteger() and IntegerToDate() functions.

NextPTODate = IntegerToDate(DateToInteger(EDT_NextPTODate) + 180)

DaysLeft = IntegerToDate(DateToInteger(NextPTODate) - DateToInteger(DateSys()))

Regards
Al



Edited 2 time(s). Last edit at 03/28/2022 06:49PM by Al.
Hi Everyone

Thank you all for replying. My apology if I didn't explain it correctly. I'm still very new and need to learn a lot.

Pao

The correct answer is showing in the POPUP window which is correct but then I still had to type it in, in the NextPTODate field that was created in my data file. I want the NextPTODate to be filled in automatically after I completed the CurrentPTODate + 180 days. Hope you understand what I mean by this.

Argus

I do understand the format settings of the fields. It's just I did not know about the Date format should be YYYY/MM/DD but I did read it up in the help section and change my dates format and then it was fixed. Sorry for the inconvenience but the fault was me as I did not read the help fully and only looked at the code within the help section.

Al
Thanks Al I'm going to use this format.

Regards
Kobus
You can do it in several ways, depedening if the controls in the form are linked to the data file fields or not.

Manual way:
YOUR_DATA_FILE_NAME.NextPTODate=EDT_NextPTODate

Try to follow all the tutorial and check the examples provide with windev you can learn a lot from it.
Other possoble way to learn how to work with form, data files and so is to create one project with one or two simple data files, create form using the RAD and check how they work

Regards

Paulo Oliveira
it's NOT YYYY/MM/DD, the internal/machine/return format should always be YYYYMMDD (no slash)
Hi

Thanks Pao for the advise. I should do that as I need more solutions. Don't want to ask every time here for help. Thank you also Argus its YYYYMMDD without the slashes my mistake. I did do it like this.

Thank you for helping. I appreciate it.

Regards
Kobus
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: