Re: Problem parsing date formats using Import
- To: mathgroup at smc.vnet.net
- Subject: [mg90508] Re: [mg90458] Problem parsing date formats using Import
- From: Curtis Osterhoudt <cfo at lanl.gov>
- Date: Fri, 11 Jul 2008 02:03:59 -0400 (EDT)
- Organization: LANL
- References: <200807101033.GAA15271@smc.vnet.net>
- Reply-to: cfo at lanl.gov
Hi, Jon, If a date like 20080101 gives you something like {1900, 8, 21, 9, 48, 21.} that's because Mathematica is treating the original number as the number of seconds since Jan 01, 1900. I usually, if I have a consistent format of dates, prefer to write a parsing function myself -- it's usually much faster than relying on Mathematica. The program has to figure out if something is a date, and then figure out what the format is (heuristically?) and then do the translation. And, so far as I know, it has to do this on every number it encounters in a long list of dates. Slow! If you still want to have Mathematica parse dates like 20080101 as Jan 01, 2008, then turn them into strings! In[28]:= DateList["20080101"] Out[28]= {2008, 1, 1, 0, 0, 0.} Best wishes, C.O. On Thursday 10 July 2008 04:33:43 Jon wrote: > Hi, > > 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? > > Thanks and regards, > Jon Rowland > > In[137]:= ImportString["1982-04-22\n1982-04-23", "Table", > "DateStringFormat" -> {"Year", "-", "Month", "-", "Day"}] > Out[137]= {{{1982, 4, 22}}, {{1982, 4, 23}}} > > In[138]:= ImportString["198204-22\n198204-23", "Table", > "DateStringFormat" -> {"Year", "Month", "-", "Day"}] > Out[138]= {{{1982, 4, 22}}, {{1982, 4, 23}}} > > In[139]:= ImportString["19820422\n19820423", "Table", > "DateStringFormat" -> {"Year", "Month", "Day"}] > Out[139]= {{19820422}, {19820423}} -- ========================================================== Curtis Osterhoudt cfo at remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 Please avoid sending me Word or PowerPoint attachments See http://www.gnu.org/philosophy/no-word-attachments.html ==========================================================
- References:
- Problem parsing date formats using Import
- From: Jon <rowland.jon@gmail.com>
- Problem parsing date formats using Import