Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7793 > unrolled thread

split a number to Date format

Started byDerek Martin <cdmartin@me.com>
First post2012-01-14 07:56 +0000
Last post2012-01-14 22:23 +0000
Articles 4 — 4 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  split a number to Date format Derek Martin <cdmartin@me.com> - 2012-01-14 07:56 +0000
    Re: split a number to Date format Peter Breitfeld <phbrf@t-online.de> - 2012-01-14 22:10 +0000
    Re: split a number to Date format "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2012-01-14 22:18 +0000
    Re: split a number to Date format "Dr. Wolfgang Hintze" <weh@snafu.de> - 2012-01-14 22:23 +0000

#7793 — split a number to Date format

FromDerek Martin <cdmartin@me.com>
Date2012-01-14 07:56 +0000
Subjectsplit a number to Date format
Message-ID<jercf9$1aa$1@smc.vnet.net>
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

[toc] | [next] | [standalone]


#7816

FromPeter Breitfeld <phbrf@t-online.de>
Date2012-01-14 22:10 +0000
Message-ID<jesufr$cff$1@smc.vnet.net>
In reply to#7793
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
>

Maybe like this:

In[59]:= dorg = "111205020000"

Out[59]= "111205020000"

In[63]:= ds = 
 ToExpression /@ 
  MapAt[StringJoin["20", #] &, 
   StringJoin /@ Partition[Characters[dorg], 2], 1]

Out[63]= {2011, 12, 5, 2, 0, 0}

In[64]:= DateString[ds]

Out[64]= "Mon 5 Dec 2011 02:00:00"

-- 
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de

[toc] | [prev] | [next] | [standalone]


#7835

From"Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com>
Date2012-01-14 22:18 +0000
Message-ID<jesuv5$cn6$1@smc.vnet.net>
In reply to#7793
On Sat, 14 Jan 2012 07:56:25 -0000, Derek Martin <cdmartin@me.com> 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
>

How about

FromDigits /@ Partition[IntegerDigits[111205020000], 2]

   ?

[toc] | [prev] | [next] | [standalone]


#7847

From"Dr. Wolfgang Hintze" <weh@snafu.de>
Date2012-01-14 22:23 +0000
Message-ID<jesv9l$cp2$1@smc.vnet.net>
In reply to#7793
"Derek Martin" <cdmartin@me.com> schrieb im Newsbeitrag 
news:jercf9$1aa$1@smc.vnet.net...
>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
>

Not very elegant, but it works
In[2]:=
dn = 111205020000
Out[2]=
111205020000

In[3]:=
ds = StringJoin["20", ToString[dn]];
(Prepend[Table[StringTake[#1, {i, i + 1}], {i, 5, StringLength[#1] - 1, 
2}],
StringTake[#1, {1, 4}]]& )[ds]
Out[3]=
{"2011", "12", "05", "02", "00", "00"}

Regards,
Wolfgang

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web