Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: Formatted Date String

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67142] Re: [mg67106] Formatted Date String
  • From: János <janos.lobb at yale.edu>
  • Date: Sat, 10 Jun 2006 04:53:56 -0400 (EDT)
  • References: <200606090509.BAA11297@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Jun 9, 2006, at 1:09 AM, . 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!

Here is a newbie approach:

In[1]:=
lst = Table[Date[i], {i, 10}]
Out[1]=
{{2006, 6, 9, 17, 25,
    55.108156`8.493790853294643\
}, {2006, 6, 9, 18, 25,
    55.108217`8.493791334021102\
}, {2006, 6, 9, 19, 25,
    55.108227`8.493791412828665\
}, {2006, 6, 9, 20, 25,
    55.108237`8.493791491636221\
}, {2006, 6, 9, 21, 25,
    55.108246`8.493791562563004\
}, {2006, 6, 9, 22, 25,
    55.108256`8.493791641370525\
}, {2006, 6, 9, 23, 25,
    55.108265`8.493791712297286\
}, {2006, 6, 10, 0, 25,
    55.108275`8.493791791104785\
}, {2006, 6, 10, 1, 25,
    55.108285`8.493791869912268\
}, {2006, 6, 10, 2, 25,
    55.108294`8.493791940838982\
}}

In[2]:=
(StringJoin[Switch[#1[[2]],
      1, "January", 2,
      "February", 3, "March",
      4, "April", 5, "May", 6,
      "June", 7, "July", 8,
      "August", 9,
      "September", 10,
      "October", 11,
      "November", 12,
      "December"], " ",
     ToString[#1[[3]]], ",",
     ToString[#1[[1]]]] & ) /@
   lst
Out[2]=
{"June 9,2006",
   "June 9,2006",
   "June 9,2006",
   "June 9,2006",
   "June 9,2006",
   "June 9,2006",
   "June 9,2006",
   "June 10,2006",
   "June 10,2006",
   "June 10,2006"}

János


----------------------------------------------
Trying to argue with a politician is like lifting up the head of a  
corpse.
(S. Lem: His Master Voice)


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