Ask Your Question

Convert string to date [closed]

asked 2018-10-15 23:25:45 +0200

yonder gravatar image

updated 2018-10-16 05:05:01 +0200

EasyTrieve gravatar image

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
edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by yonder
close date 2018-10-16 01:45:15.070336

1 Answer

Sort by » oldest newest most voted

answered 2018-10-16 00:12:19 +0200

Ratslinger gravatar image

updated 2018-10-16 00:28:15 +0200


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


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]

edit flag offensive delete link more


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

yonder gravatar imageyonder ( 2018-10-16 01:38:03 +0200 )edit

Question Tools

1 follower


Asked: 2018-10-15 23:25:45 +0200

Seen: 65 times

Last updated: Oct 16 '18