4

Date() function in Julia with Examples

 3 years ago
source link: https://www.geeksforgeeks.org/date-function-in-julia-with-examples/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Date() function in Julia with Examples
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)

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)

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)

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)

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK