MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: list of dates

On 5/2/08 at 3:42 AM, roger.nye at (Roger Nye) wrote:

>Hi, I have a list of dates in the format YYYY-MM-DD and I want to
>convert them to a decimal value, so 1963-01-01 goes to 63.0 and
>1985-07-01 goes roughly to 85.5.

>Any suggestions on the best way to do this?

In[1]:= << Units`
yearSeconds = First@SI[1 Year]

Out[2]= 31536000

In[3]:= fractionalYear[dateString_] :=
  Mod[AbsoluteTime@dateString, yearSeconds]/yearSeconds

In[4]:= (ToExpression[StringTake[#, {3, 4}]] +
fractionalYear[#]) &@
   "1963-01-01" // N

Out[4]= 63.0411

In[5]:= (ToExpression[StringTake[#, {3, 4}]] +
fractionalYear[#]) &@
   "1985-07-01" // N

Out[5]= 85.5534

Season to taste

  • Prev by Date: Re: function to check if array is empty
  • Next by Date: Re: Wolfram Workbench user experiences
  • Previous by thread: Re: list of dates
  • Next by thread: Re: list of dates