Re: Re: list of dates

• To: mathgroup at smc.vnet.net
• Subject: [mg88365] Re: [mg88353] Re: list of dates
• From: Stern <nycstern at gmail.com>
• Date: Sat, 3 May 2008 06:15:25 -0400 (EDT)
• References: <fvegu1\$5e9\$1@smc.vnet.net> <200805021003.GAA09008@smc.vnet.net>

```The following will be accurate within any given year, though depending on
your purposes, it may not be good for date math as different years are of
different lengths --

dateToFloat3[datestring_] :=
Module[{ourdate, yearstart, yearend},
ourdate = Take[DateList[datestring], 3]; yearstart = {ourdate[[1]], 1, 1};

yearend = {ourdate[[1]], 12,
31}; (ourdate[[1]] -
1900) + (AbsoluteTime[ourdate] -
AbsoluteTime[yearstart])/(AbsoluteTime[yearend] -
AbsoluteTime[yearstart]) // N]

(* coded for clarity, you could make it shorter and probably quicker if you
wanted *)

dateToFloat3["1963-01-01"]

63.

dateToFloat3["1963-12-31"]

64.

dateToFloat3["1963-07-01"]

63.4959

Michael

On Fri, May 2, 2008 at 6:03 AM, Jean-Marc Gulliet <
jeanmarc.gulliet at gmail.com> wrote:

> Roger Nye wrote:
>
> > 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?
>
> To help you started, the following function assume an input date as a
> string and that a year as 360 days (i.e. 12 months of 30 days).
>
> myDate[d_String] := Module[{yy, mm, dd},
>   {yy, mm, dd} = DateList[d][[1 ;; 3]];
>   yy = yy - 1900;
>   td = 30 (mm - 1) + dd;
>   yy + Rescale[td, {1, 360}] // N
>   ]
> myDate["1963-01-01"]
> myDate["1985-07-01"]
>
> Out[79]= 63.
>
> Out[80]= 85.5014
>
> Regards,
> -- Jean-Marc
>
>

```

• Prev by Date: Re: Wolfram Workbench user experiences
• Next by Date: Re: Help with Manipulate
• Previous by thread: Re: list of dates
• Next by thread: Re: list of dates