MathGroup Archive 2007

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

Search the Archive

RE: date format


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.


  • 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