Convert string to date

So, I am at wits end on this question. I have a date picker in a writer document/form. I can read the chosen date easily enough (01/03/18). I can then break it down into a comma separated format easily enough (2018,01,03). Now the funk happens. When I try DateSerial() function it says no way - invalid function call. As overview, DateSerial(2018,01,03) works properly but a string created using Left, Mid, Right will not work?

today = ThisComponent.Drawpage.Forms.getByName("Form").getByName("dteDatePick").tex

NewString= "20" + right(today,2) + ","
NewString = NewString + left(today,2)+ ","
NewString = NewString + mid(today,4,2) 

Print trim(NewString) 'gives the correct response


MsgBox DateSerial(NewString) 'gives invalid procedure call

Hello,

DateSerial takes three arguments - Year month and day. These three arguments are separated by commas. When you state:

DateSerial(2018,01,03)

2018,01,03 is NOT a string but rather three numeric figures separated by commas. To get the results you want you need to extract the necessary data from today;

currMonth = Month(today)
currDay = Day(today)
currYear = Year(today)

Now you also must define the result wanted - defined as a string will return mm/dd/yy & defined as long will return nnnnn.

So for a serial number returned:

Sub Main
    Dim serialDate as Long
    today = ThisComponent.Drawpage.Forms.getByName("Form").getByName("dteDatePick").text
    currMonth = Month(today)
    currDay = Day(today)
    currYear = Year(today)
    serialDate = DateSerial( currYear, currMonth, currDay )
    MsgBox serialDate 
End Sub

See also → DateSerial Function [Runtime]

Oh, for crying outloud. Of Course. (Picture hand striking forehead). The solution worked perfectly. I modified it so that selection of a date from date picker would populate a form with several calculated future dates, based on the selection. BIG think you