Input current datetime as a default

 
input datetime   InpDateTime = TimeLocal();

I would like the input panel to always show the current date as the default value when prompting for a date.

However, when I write the above, I get an error. What can I do?

 

Dear Nagisa, this issue has also been puzzling me. I tried many ideas to no avail, it seems to be impossible to cause a datetime input to show the current date.

The best remedy I could get was to initialize with -1. The input will show as 1.1.1970 in the mask, but if you tick it it will instantly jump to the current time. In the code I also compare it with -1 to take action on default.

Best regards

 
lippmaje:

Dear Nagisa, this issue has also been puzzling me. I tried many ideas to no avail, it seems to be impossible to cause a datetime input to show the current date.

The best remedy I could get was to initialize with -1. The input will show as 1.1.1970 in the mask, but if you tick it it will instantly jump to the current time. In the code I also compare it with -1 to take action on default.

Best regards

Oh, I see, indeed!

It looks like this is the only way.

Thank you very much.

 
You're welcome.
 
input datetime   InpDateTime = TimeLocal();

That can not be done, since you must initialize global/static variables with a constant.

input string      dateTime = "Today";  // When YYYY.MM.DD
      datetime InpDateTime;
int OnInit(){
   InpDateTime = dateTime == "Today" ? TimeLocal() : StringToTime(dateTime);
   ⋮
 
William Roeder:

That can not be done, since you must initialize global/static variables with a constant.

Thank you for your advice, it is much appreciated.

I considered a similar method but decided not to adopt it due to the hassle of entering different dates and not being able to use the calendar.

Reason: