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 integerReturns: A date of fixed format.
Below examples illustrate the use of above function:
Example 1:
# Date function in juliadate = Date(Dates.Year(2019), Dates.Month(01), Dates.Day(26)) # Printing the dateprintln(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 function in juliadate = Date(2020, 07, 7) # Printing the dateprintln(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 function in juliadate = Date(2020, 07) # Printing the dateprintln(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 function in juliadate = Date() # Printing the dateprintln(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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.


