# Iterate over days of year to make a list/graph

How do I make a graph of a function which takes a date as input, over a full year?

 To clarify, I have an existing function, say f, which takes a date as input and returns a value between 0 and 90. I want to plot this function over the year 2016, so plot the value for every day in 2016.

My try

I can reduce this question to making a list like

Table[
{d, f[d]},
{d, DateObject[{2016, 1, 1}], DateObject[{2016, 12, 31}]}
]


and then doing ListPlot or something, but obviously I need to give Mathematica at least the step size (one day) and find a way to add a day to a date in such an iteration.

Maybe DateRange is an idea to make a list of dates of a year, but not sure how I would attach my function to that properly.

PS I'm on Mathematica 11.0

 As per request, my own function is a little big too put here, but for example function

g[d_] := (
DateValue[d, "Month"] + DateValue[d, "Day"]
)


Will do, I guess.

• what do you want your graph to look like? Aug 20 '16 at 16:22
• I'm guessing you want date on x axis? what do you want on y axis? Aug 20 '16 at 16:23
• @ConorCosnett (sorry for the delay) No sorry I think you misinterpreted the question, I'm asking how to make a graph of a function which takes a date as input, I already have a (big) function which works fine, it returns a value between 0 and 90 given a date. I'll try to clarify the question, hope it helps Aug 20 '16 at 17:06
• @ConorCosnett Edited question for example function Aug 20 '16 at 17:21
• I fixed my function now @PHPirate Aug 20 '16 at 17:21

## solution with DateListPlot

Clear[f,g]
f = Function[x, DateObject[{2016, 1, 1}] + Quantity[(x-1), "Days"]]
g[d_] := (DateValue[d, "Month"] + DateValue[d, "Day"])
listOfDates = Table[{f[d], g[f[d]]}, {d, 1, 365}];

DateListPlot[listOfDates] ListPlot[Table[g[f[d]], {d, 1, 365}]] Here is a function which you give 1 to return the first day 1 in 2016 ect.

use Quantity

f = Function[x, DateObject[{2016, 1, 1}] + Quantity[(x-1), "Days"]]

Table[{f[d], g[f[d]]}, {d, 1, 365}] • For me, the addition of dates doesn't work... I get back for f the date plus days, so 3 + DateObject[{2015, 12, 31}] (Oh, I'm on MMa 11, if that is relevant) Aug 20 '16 at 16:29
• @PHPirate Could you describe the output of your function? Aug 20 '16 at 16:44
• Oh I just saw it, yes that works, but is there a possibility to put some real dates on the x-axis instead of day of year? Just for the fancy looks... Maybe the month? Aug 20 '16 at 17:29
• Just googled for that, I think it should be fixed with using DateListPlot? Anyway, +1 for helping me learn that adding a number to a date doesn't work, but adding a quantity does! Aug 20 '16 at 17:32
• @PHPirate I included DateListPlot now Aug 20 '16 at 17:44