RE: Converting from string to integer and back
- To: mathgroup at smc.vnet.net
- Subject: [mg29053] RE: [mg29030] Converting from string to integer and back
- From: "David Park" <djmp at earthlink.net>
- Date: Sat, 26 May 2001 21:53:44 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Brian,
It might be easier to do this with integer arithmetic, rather than
converting to strings and back.
Here is one possible routine.
splitdate[(date1_Integer)?Positive] :=
Module[{year, month, day, date = date1},
year = IntegerPart[date/10000];
date = date - 10000*year;
month = IntegerPart[date/100];
day = date - 100*month;
{year, month, day}]
splitdate[20010525]
{2001, 5, 25}
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
> From: brian [mailto:polar at cloud9.net]
To: mathgroup at smc.vnet.net
>
> Is there an easy way to convert an integer to a string and then back to
> an integer? I have a file containing dates in the YYYYMMDD format. I
> want to convert these dates to {YYYY, MM, DD} so that I can some of the
> functions in the misc`Calendar package. But at this point I am lost as
> to how to split the date into year,month, day. StringTake is the only
> way I could think of but doesn't work as the head of the date is
> integer. If there was a way to convert the date to a string I can split
> the date and then convert this back to an integer but I have seen no
> treatment of anything like this in the books I have. I guess I'm a
> little more used to handling text in perl. Any help while I'm riding up
> the learning curve is greatly appreciated.
>
> Brian Meehan
>
>