Open In App

Date() function in Julia with Examples

Improve
Improve
Like Article
Like
Save
Share
Report

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 function in julia
date = Date(Dates.Year(2019), Dates.Month(01), Dates.Day(26))
  
# Printing the date
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 function in julia
date = Date(2020, 07, 7)
  
# Printing the date
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 function in julia
date = Date(2020, 07)
  
# Printing the date
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 function in julia
date = Date()
  
# Printing the 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.



Last Updated : 26 Aug, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads