Related Articles

Related Articles

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Date function in julia
date = Date(Dates.Year(2019), Dates.Month(01), Dates.Day(26))
  
# Printing the date
println(date)

chevron_right



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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Date function in julia
date = Date(2020, 07, 7)
  
# Printing the date
println(date)

chevron_right



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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Date function in julia
date = Date(2020, 07)
  
# Printing the date
println(date)

chevron_right



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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Date function in julia
date = Date()
  
# Printing the date
println(date)

chevron_right



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.




My Personal Notes arrow_drop_up
Recommended Articles
Page :