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