MathGroup Archive 2006

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

Search the Archive

Re: Formatted Date String

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67147] Re: Formatted Date String
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sat, 10 Jun 2006 04:54:17 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <e6b5tv$d57$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

. wrote:
> Hi all,
> 
> Is there an elegant way to convert the output of the Date[] function
> into other formats, like formatted strings?  Specifically, I have my
> own routine to output the results of my calculations into a specific
> file format.  I want to automatically include the date, but I want it
> in the format: <Month> <day>, <Year>.  So today's date would output
> "June 8, 2006".  I know this is easy enough to do using some brute
> force (ie create a lookup table to convert numeric months to their
> string equivalents).  However, I was hoping that a more elegant, or at
> least more native solution might be possible.
> 
> Thanks!
> 
Hello,

I am not aware of anything built-in like that. The closest related 
package is "Miscellaneous`Calendar`" [1] (conversion among different 
calendar systems, day of the week in plain English, ...) although it 
does not provide anything for month conversion. A routine like the 
following one will do what you are looking for.

In[1]:=
myDate[x___] := Module[{date, day, month, year},
    date = Date[x][[{1, 2, 3}]];
     day = ToString[date[[3]]];
     year = ToString[date[[1]]];
     month = ToString[date[[2]] /. {1 -> Jan, 2 -> Feb,
         3 -> Mar, 4 -> Apr, 5 -> May, 6 -> Jun,
         7 -> Jul, 8 -> Aug, 9 -> Sep, 10 -> Oct,
         11 -> Nov, 12 -> Dec}]; StringJoin[month, " ",
      day, ", ", year]]

In[2]:=
myDate[]

Out[2]=
Jun 9, 2006

Best regards,
/Jean-Marc

[1]: 
http://documents.wolfram.com/mathematica/Add-onsLinks/StandardPackages/Miscellaneous/Calendar.html


  • Prev by Date: Re: Selecting Real Roots, Again
  • Next by Date: Mathematica doesn't know what it's doing.
  • Previous by thread: Re: Formatted Date String
  • Next by thread: Selecting Real Roots, Again