Date() function in Julia with Examples
Last Updated :
26 Aug, 2020
Date() function in Julia works like a Constructors. The date can be constructed by Period types or integer by parsing the given period and integer. By default, it returns 0001-01-01
. The first four digits represent the year, the next two digits represent the month and last two digits represent the day.
Syntax:
Date(YYYY-MM-DD)
or
Date(Dates.Year(YYYY), Dates.Month(MM), Dates.Day(DD))
where,
YYYY-4 digit integer
MM-2 digit integer
DD-2 digit integer
Returns: A date of fixed format.
Below examples illustrate the use of above function:
Example 1:
date = Date(Dates.Year( 2019 ), Dates.Month( 01 ), Dates.Day( 26 ))
println(date)
|
Output:
2019-01-26
In the above code, all the parameters are passed to the Date() function and it returns a date format.
Example 2:
date = Date( 2020 , 07 , 7 )
println(date)
|
Output:
2020-07-07
In this example, all the parameters are passed in a comma separated format and it returns date in specific default format.
Example 3:
date = Date( 2020 , 07 )
println(date)
|
Output:
2020-07-01
In the above code, only two of the parameter(YYYY, MM) is passed in comma separated format and it returns a date format with the default day 01.
Example 4:
date = Date()
println(date)
|
Output:
0001-01-01
In this example, no parameter(YYYY, MM) is passed and it returns a date format with the default date 0001-01-01.
Share your thoughts in the comments
Please Login to comment...