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
  • Subject: [mg124246] Re: split a number to Date format
  • From: "David Park" <djmpark at>
  • Date: Sat, 14 Jan 2012 17:09:43 -0500 (EST)
  • Delivered-to:
  • References: <29981906.61970.1326529492115.JavaMail.root@m06>


Basically you want to use RealDigits to extract the digits from the number
and then work with them. Paste the following into a notebook and evaluate:

Partition[%, 2] 
FromDigits /@ % 
MapAt[# + 2000 &, %, 1] 

You can then wind this up backwards, replacing each % by the previous entry
and the number by a variable, to obtain a one-liner definition:

toDateString[number_] := 
  MapAt[# + 2000 &, 
   FromDigits /@ Partition[First[RealDigits[number]], 2], 1]] 

Mon 5 Dec 2011 02:00:00 

Or it may be easier to write a more explicit form of the function using

toDateString[number_] :=
  work = First[RealDigits[number]];
  work = Partition[work, 2];
  work = FromDigits /@ work;
  work = MapAt[# + 2000 &, work, 1];

Mon 5 Dec 2011 02:00:00 

David Park
djmpark at 

From: Derek Martin [mailto:cdmartin at] 

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

  • Prev by Date: Re: Plotting a line with color changing as a function of position
  • Next by Date: Re: split a number to Date format
  • Previous by thread: Re: split a number to Date format
  • Next by thread: Function return type in Compile