How can three int variables, start_year, start_month, and start_day, which are 2024, 3, and 4 respectively, be concatenated into a date variable (date)?
date(start_year, start_month, start_day)
The script above aborted with an error:
Syntax Error: [line #1] The function [date] expects 0~1 argument(s), but the actual number of arguments is: 3.
The following script also failed:
date(concat([start_year, start_month, start_day],'.'))
=> Failed to convert the string to DATE
Because the month and day must be two-digit values.
Later, I came up with a solution, but it's quite complicated:
def pad_with_zero(num){
res = string(num)
if(strlen(res) == 1) res = concat('0',res)
return(res)
}
date(concat([start_year, pad_with_zero(start_month), pad_with_zero(start_day)],'.'))
Is there a simpler method that can achieve this with just one function?
You can pad 0 to meet the date format specifications of DolphinDB.