Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #7820 > unrolled thread
| Started by | "David Park" <djmpark@comcast.net> |
|---|---|
| First post | 2012-01-14 22:12 +0000 |
| Last post | 2012-01-14 22:12 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: split a number to Date format "David Park" <djmpark@comcast.net> - 2012-01-14 22:12 +0000
| From | "David Park" <djmpark@comcast.net> |
|---|---|
| Date | 2012-01-14 22:12 +0000 |
| Subject | Re: split a number to Date format |
| Message-ID | <jesujn$che$1@smc.vnet.net> |
Derek,
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:
RealDigits[111205020000]
First[%]
Partition[%, 2]
FromDigits /@ %
MapAt[# + 2000 &, %, 1]
DateString[%]
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_] :=
DateString[
MapAt[# + 2000 &,
FromDigits /@ Partition[First[RealDigits[number]], 2], 1]]
toDateString[111205020000]
Mon 5 Dec 2011 02:00:00
Or it may be easier to write a more explicit form of the function using
Module:
toDateString[number_] :=
Module[{work},
work = First[RealDigits[number]];
work = Partition[work, 2];
work = FromDigits /@ work;
work = MapAt[# + 2000 &, work, 1];
DateString[work]
]
toDateString[111205020000]
Mon 5 Dec 2011 02:00:00
David Park
djmpark@comcast.net
http://home.comcast.net/~djmpark/index.html
From: Derek Martin [mailto:cdmartin@me.com]
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
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web