Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Julia: The Day of Week defaults to Monday=1, How to set Sunday=1

Tags:

date

julia

In the Julia 1.0 documentation for the Dates package it says for the Dates.dayofweek function:

"Return the day of the week as an Int64 with 1 = Monday, 2 = Tuesday, etc.."

Example from documentation after adding using Dates:

julia> using Dates
julia> Dates.dayofweek(Date("2000-01-01"))
6

Example for Monday, 9/10/2018:

julia> Dates.dayofweek(Date("2018-09-10"))
1

I do not see a way to set Sunday=1, Monday=2, etc.

Any suggestions?

EDIT: The accepted answer works great and is illustrated below in contrast to the code above:

julia> my_dayofweek(Date("2018-09-10"))
2
like image 227
Julia Learner Avatar asked Sep 02 '25 15:09

Julia Learner


1 Answers

This functionality is hard coded. Therefore I guess that what you can do is define your own function for this:

my_dayofweek(x) = dayofweek(x + Day(1))
like image 161
Bogumił Kamiński Avatar answered Sep 05 '25 16:09

Bogumił Kamiński



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!