Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

Re: split a number to Date format

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124273] Re: split a number to Date format
  • From: Michael Stern <nycstern at gmail.com>
  • Date: Sun, 15 Jan 2012 04:50:26 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201201140754.CAA01282@smc.vnet.net>

Are these coming in as strings, or integers? Are they always the same 
length? Is the year always after 2000? I can't provide a general formula 
without knowing more about the source data but the following may help. I 
assume you start with an integer, so I convert it to a string, then 
break that into a list of characters, group them into a list of pairs, 
convert each pair back to integers, then add 2000 to the first element 
in the list.

In[1]:= testnumber = 111205020000;

In[2]:= Map[ToExpression[StringJoin[#]] &,
  Partition[Characters[ToString[testnumber]], 2]] + {2000, 0, 0, 0, 0, 0}

You can pass the output from that through DateString[] if you need; I generally prefer to leave dates in list format where possible.

Michael Stern

On Jan 14, 2012, at 2:54 AM, Derek Martin wrote:

> I have experimental data in spreadsheet format.  The first column is a time stamp in the format 111205020000. 
> If I could parse or split the number 111205020000 into {11,12,05,02,00,00} and replace the first 11 with 2011, the Date commands would work fine. I can do the replacing, but am having difficulty seeing how to split the number into  {11,12,05,02,00,00}.
>
> DateString[{2011, 12, 05, 02, 00, 00}] gives
> "Mon 5 Dec 2011 02:00:00"
>
> Any help to convert my number to the right Date format would be appreciated. I am using Mathematica 8.
>
> Thanks in Advance
> Derek
>




  • Prev by Date: Re: how can one use mathematica get the approximate derivative of {x,y} data points?
  • Next by Date: Re: NDSolve output without interpolating function
  • Previous by thread: Re: split a number to Date format
  • Next by thread: Re: split a number to Date format