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

MathGroup Archive 2008

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

Search the Archive

Re: Problem parsing date formats using Import

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90497] Re: Problem parsing date formats using Import
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Fri, 11 Jul 2008 02:01:50 -0400 (EDT)
  • References: <g54oft$eqq$1@smc.vnet.net>

Jon wrote:

> I'm trying to parse a file which has dates in the format YYYYMMDD,
> e.g. 20080101. However I just can't seem to get the DateStringFormat
> to work - it works fine for YYYY-MM-DD or YYYYMM-DD but not if I
> remove the separators entirely. Is this because of the ambiguity
> between numeric and this date format? Does the automatic date parsing
> not work for entirely numeric date formats?

<snip>

When no separators at all are specified for the input string, DateString 
and related functions think they are assumed:

     DateString[{"07/10-2008", {"Month", "Day", "Year"}}]

     "Thu 10 Jul 2008 00:00:00"

You can extract the year, month, and day, by first converting the data 
into strings, then taking the desired peaces, and converting back the 
elements of the resulting list into numbers.

     data = ImportString["19820422\n19820423", "Table"];

     ToExpression[{StringTake[#, 4], StringTake[#, {5, 6}],
         StringTake[#, -2]}] & /@ ToString @@@ data

     {{1982, 4, 22}, {1982, 4, 23}}

Regards,
-- Jean-Marc


  • Prev by Date: Re: Import/Export Problem
  • Next by Date: How to replace TextListPlot ?
  • Previous by thread: Re: Problem parsing date formats using Import
  • Next by thread: Import/Export Problem