# DiffEquations and DateTime abscissa

**URL:** <https://discourse.julialang.org/t/diffequations-and-datetime-abscissa/48738>\
**Category:** New to Julia\
**Created:** [October 21, 2020, 10:26am UTC](https://discourse.julialang.org/t/diffequations-and-datetime-abscissa/48738 "2020-10-21T10:26:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [October 21, 2020, 10:26am UTC](https://discourse.julialang.org/t/diffequations-and-datetime-abscissa/48738/1 "2020-10-21T10:26:28Z")

</div>

I’m solving an ODE, and want to change the time axis (abscissa) to a Date – or rather: DateTime.

```julia
using Plots, Dates, DifferentialEquations
#
# test case
tust!(x,p,t) = -x/p + 2sin(t*2pi)
#
x0 = 3.
p = 0.5
tspan=(0.,10)
prob = ODEProblem(tust!,x0,tspan,p)
sol = solve(prob)

```

I can transform the solution by:

```julia
mymap(t,x) = (t,-2x)
plot(sol,vars=(mymap,0,1))

```

leading to:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/3/93e5707fd7e93c9291a6663f903c2d219cd97add.png)  
I can do a “manual” plotting with dates:

```julia
function timeperiod(x::Float64)
    Second(Int(floor(Second(Day(1)).value * x)))
end
#
tm = DateTime(2020,10,21) + timeperiod.(sol.t)
plot(tm,Array(sol))

```

leading to

 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/9/89e7b725cf16a09f267e14a942b156189af71a0d.png)

However, if I try to do the following:

```julia
mymap2(t,x) = (DateTime(2020,10,21) + timeperiod(t),-2x)
#
plot(sol,vars=(mymap2,0,1))

```

this does not work… I get the following:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/8/a851318dd1dd5d61105cb4a73650c01bbbc476d9.png)

**Question** : how can I fix this so that I use the plotting recipe of DifferentialEquations and maintain the smoothness of the interpolation of DifferentialEquations?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [October 24, 2020, 6:33am UTC](https://discourse.julialang.org/t/diffequations-and-datetime-abscissa/48738/2 "2020-10-24T06:33:16Z")

</div>

What about directly solving where time itself is a date time? Does that actually work? If so… that might be the easiest way to do this.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [October 24, 2020, 10:09am UTC](https://discourse.julialang.org/t/diffequations-and-datetime-abscissa/48738/3 "2020-10-24T10:09:50Z")

</div>

Interesting idea. I’ll check. I have solved the problem for now using the interpolating solution for up-sampling – works fine.
