Android Question Given date + x months

Fab117

Member
Licensed User
Longtime User
Hi,
In my application, I have 2 edit Text inputs:
Private edtDateCongel As EditText ' will propose as default the current date and will receive from user the date to use for calculation
Private edtValidite As EditText ' will propose a default value extracted for a SQLite db and will receive the number of months to use for calculation​

Both edit text inputs are stored in variable:
Private DateDeCongelation As String
Private ValiditeChoisie As Int
DateDeCongelation = edtDateCongel.Text ' Correspond to the date when the article has been frozen
ValiditeChoisie = edtValidite.Text ' Correspond to the number of months the article can be kept​

And I would like to store the calculation in a new variable:
Private ExpiryDate As String​

The calculation being the input date (stored in variable "DateDeCongelation") + the number of months (stored in variable "ValiditeChoisie ")

I know that I am completely wrong with the type of variables I declared.

I tried to find the solution in other threats without success.

Do someone know how I could solve my issue ?

Regards,

Fab
 
Hello @Fab117

Is this what you are looking at doing?
Code: Copy
    Dim ValiditeChoisie As Int = 6
    Dim DateDeCongelation As String = "1/9/2015" ' or a some other valid format
    Dim dcalc As Long
    dcalc = DateTime.Add(DateTime.DateParse(DateDeCongelation), 0, ValiditeChoisie, 0)
    Dim ExpiryDate As String = DateTime.Date(dcalc)
    Log(ExpiryDate)
 
Upvote 0
Hello Ed,
Thank you for your help.
Your code is working perfectly.
If you have still few minutes, could you please explain me the line :

= DateTime.Add(DateTime.DateParse(DateDeCongelation), 0, ValiditeChoisie, 0)

Fab
 
Upvote 0
Upvote 0
Back
Top