Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2001

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

Search the Archive

Re: Converting from string to integer and back

  • To: mathgroup at smc.vnet.net
  • Subject: [mg29080] Re: Converting from string to integer and back
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sun, 27 May 2001 18:04:45 -0400 (EDT)
  • References: <9ekt8b$7u9@smc.vnet.net> <NL0Q6.1425$E6.8238@ralph.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

> The following code should work for dates between the years 1000 and 9999
>
> meehan[i_Integer]:=
>   Map[FromDigits[Take[IntegerDigits[i,10],#],10]&,{{1,4},{5,6},{7,8}}]
>
> Seth J. Chandler

Seth,

Restriction is removed by

listdate[dt_] :=
  FromDigits[
        Part[Take[IntegerDigits[dt], #]]] & /@ {{1, -5}, {-4, -3}, {-2, -1}}


listdate[20010519]

{2001,5,19}

listdate[310519]

{31,5,19}

listdate[1234560519]

{123456,5,19}

--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Seth Chandler" <SChandler at Central.UH.Edu> wrote in message
news:NL0Q6.1425$E6.8238 at ralph.vnet.net...
> The following code should work for dates between the years 1000 and 9999
>
> meehan[i_Integer]:=
>   Map[FromDigits[Take[IntegerDigits[i,10],#],10]&,{{1,4},{5,6},{7,8}}]
>
> Seth J. Chandler
>
> "brian" <polar at cloud9.net> wrote in message
news:9ekt8b$7u9 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: Trouble modif. Matrix in function
  • 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: ListPlot Points