MathGroup Archive 2001

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

Search the Archive

RE: Converting from string to integer and back


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
>
>



  • Prev by Date: Re: Converting from string to integer and back
  • Next by Date: Re: Can this be made cleaner and more efficient?
  • Previous by thread: Re: Converting from string to integer and back
  • Next by thread: Re: Converting from string to integer and back