In [1]:
using Dates
include("printmat.jl")
Out[1]:
In [2]:
dNb = Date(2014,1,1):Dates.Month(1):Date(2014,12,1) #build a monthly calendar
println("Dates and day of the week")
printmat([dNb Dates.dayofweek.(dNb)])
In [3]:
csvDate = [20160331;20160401] #two dates
jlDate = Date.(string.(csvDate),"yyyymmdd") #convert to string and then Julia Date
printmat(jlDate)
In [4]:
xlsDate = [DateTime(2016,3,31);DateTime(2016,4,1)] #to be converted
jlDate = Date.(xlsDate)
println("\nDateTime and then converted to Date:")
printmat(xlsDate)
printmat(jlDate)
In [5]:
dNml = [736420.0;736421.0] #to be converted, 2016-03-31;2016-04-01
jlDate = round.(Int,dNml) .- 366
jlDate = Date.(Dates.rata2datetime.(jlDate))
println("\nmatlab datenum and correct Julia Date:")
printmat([dNml jlDate],width=12)
In [6]:
d1 = Date(2016,3,31)
d2 = Date(2016,4,30)
dif = d2 - d1 #count the number of days between d2 and d1
difRel = Dates.value(dif)/Dates.daysinyear(d1) #Dates.value() is the datenumber
println("difference between two dates: ",dif)
printlnPs("as a fraction of the year: ",difRel)
In [7]:
d3 = d1 + Dates.Month(1) #one month after d1
println("d1 and one month later: ",d1," ",d3)
In [8]:
println("day of the week of date: ",d1," ",Dates.dayofweek(d1))
println("day of the year of date: ",d1," ",Dates.dayofyear(d1))
(y,m,d)= Dates.yearmonthday(d1) #splitting up a date
println("Splitting up a date ",y," ",m," ",d)
In [9]:
println(Dates.format(d1,"d u yyyy"))
println(Dates.format(d1,"dd-mm-yyyy"))
In [ ]: