MathGroup Archive 2007

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

Search the Archive

RE: date format

  • To: mathgroup at smc.vnet.net
  • Subject: [mg75124] RE: [mg75108] date format
  • From: "David Annetts" <davidannetts at aapt.net.au>
  • Date: Wed, 18 Apr 2007 04:56:13 -0400 (EDT)
  • References: <200704170026.UAA09012@smc.vnet.net>

Hi Arkadiusz

> Form the following date format
> 
> 04/Dec/2006:19:54:02
> 
> could you please show me how to get the following 
> representation {day, month, year, hour, minutes, seconds} - 
> so exactly the same as for Date[]

One approach is the following.

Define the utility function

	MonthToNum[mnth_] := Module[
	    {},
	    Return[Switch[mnth,"Jan", 1, "Feb", 2, "Mar", 3, "Apr", 4,
	        "May", 5,"Jun", 6,"Jul", 7,"Aug", 8,"Sep", 9,"Oct", 10,
              "Nov", 11, "Dec", 12]]]

Then use it in another function

	ConvertToProperDate[str_] := Module[
	    {elt, new},
	    elt = StringSplit[str, {"/", ":"}];
	    elt[[2]] = MonthToNum@elt[[2]];
	    new = {3, 2, 1, 4, 5, 6};
	    elt[[#]] & /@ new
	    ]

	tst = "04/Dec/2006:19:54:02";
	ConvertToProperDate[tst]

Key points are (i) the use of multiple delimiters in StringSplit; (ii) the
use of another function to convert months from 3 letter abbreviations to
numbers; and (iii) defining a list (new) that we can use to reorder the
output of StringSplit[].

There is no error checking above.

Regards,

Dave.


  • References:
  • Prev by Date: Re: date format
  • Next by Date: Re: Overlaying 3d plots
  • Previous by thread: RE: date format
  • Next by thread: Re: date format