MathGroup Archive 2010

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

Search the Archive

Re: Re: Date & Time format..

  • To: mathgroup at smc.vnet.net
  • Subject: [mg107777] Re: [mg107744] Re: Date & Time format..
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Thu, 25 Feb 2010 17:37:30 -0500 (EST)
  • References: <hlj414$rqp$1@smc.vnet.net> <hm322l$m95$1@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

Great. As usual, Help for DateList left out most of the options. There are  
35 on your list, but Help shows only 12.

Bobby

On Thu, 25 Feb 2010 00:53:21 -0600, Hans Michel <hmichel at cox.net> wrote:

> Graser:
>
> This combination did work after some trial and error.
>
> In[10]:= DateList[{"11/4/2009 3:24:06.303 PM",{"MonthShort","DayShort",
> "Year","Hour12Short","Minute","Second","MillisecondShort", "AMPM"}}]
>
> Out[10]= {2009,11,4,15,24,6.303}
> In[11]:= DateList[{"11/4/2009 3:24:06.303 PM",{"DayShort","MonthShort",
> "Year","Hour12Short","Minute","Second","MillisecondShort", "AMPM"}}]
> Out[11]= {2009,4,11,15,24,6.303}
>
> I think it has to do with taking into account the variable lengths and
> leading zeros of the digits in each element and upper or lower case.
>
> See the list of choices availabel for DateList and DateString
>
>        "Date" full date
>        "DateShort" full date, with short day and month names
>        "Time" full time
>        "DateTime" full date and time
>        "DateTimeShort" full date and time, with short names
>        "Year" full year (e.g. 2005)
>        "YearShort" 2-digit year (e.g. 05)
>        "QuarterName" quarter of year (e.g. "Quarter 1")
>        "QuarterNameShort" quarter of year in short form (e.g. "Q1")
>        "Quarter" quarter number (e.g. 1)
>        "MonthName" month name (e.g. "August")
>        "MonthNameShort" month name in short form (e.g. "Aug")
>        "MonthNameInitial" first letter of month name (e.g. "A")
>        "Month" 2-digit month number (e.g. 08)
>        "MonthShort" 1- or 2-digit month number (e.g. 8)
>        "DayName" day of the week (e.g. "Wednesday")
>        "DayNameShort" day of the week in short form (e.g. "Wed")
>        "DayNameInitial" first letter of day name (e.g. "W")
>        "Day" 2-digit day of the month (e.g. 09)
>        "DayShort" 1- or 2-digit day of the month (e.g. 9 or 29)
>        "Hour" 2-digit hour based on system preferences
>        "Hour12" 2-digit hour on 12-hour clock (e.g. 07)
>        "Hour24" 2-digit hour on 24-hour clock (e.g. 19)
>        "HourShort" 1- or 2-digit hour based on system preferences
>        "Hour12Short" 1- or 2-digit hour on 12-hour clock (e.g. 7)
>        "Hour24Short" 1- or 2-digit hour on 24-hour clock (e.g. 7, 19)
>        "AMPM" AM or PM
>        "AMPMLowerCase" am or pm
>        "Minute" 2-digit minute (e.g. 05)
>        "MinuteShort" 1- or 2-digit minute (e.g. 5 or 35)
>        "Second" 2-digit seconds
>        "SecondShort" 1- or 2-digit seconds
>        "SecondExact" seconds including fractions
>        "Millisecond" 3-digit milliseconds
>        "MillisecondShort" 1-, 2- or 3-digit milliseconds
>
> Quit Kernel and started again
>
> In[1]:= DateList[{"11/4/2009 3:24:06.303
> PM",{"MonthShort","DayShort","Year","Hour12Short","Minute","Second","MillisecondShort","AMPM"}}]
> Out[1]= {2009,11,4,15,24,6.303}
> In[2]:=
> DateList[{"11/4/2009 3:24:06.303
> PM",{"DayShort","MonthShort","Year","Hour12Short","Minute","Second","MillisecondShort","AMPM"}}]
> Out[2]= {2009,4,11,15,24,6.303}
>
> I tried a leading zero on the Month part to make certain that the  
> presence
> or absence of a leading zero would not affect the conversion. If this is  
> the
> case, seem a safer bet to chose the appropriate options with Short.
>
> In[3]:= DateList[{"11/04/2009 3:24:06.303
> PM",{"DayShort","MonthShort","Year","Hour12Short","Minute","Second","MillisecondShort","AMPM"}}]
> Out[3]= {2009,4,11,15,24,6.303}
>
> version
> "7.0 for Microsoft Windows (32-bit) (November 10, 2008)"
>
> Also tried on
> In[1]:= DateList[{"11/4/2009 3:24:06.303
> PM",{"DayShort","MonthShort","Year","Hour12Short","Minute","Second","MillisecondShort","AMPM"}}]
> Out[1]= {2009,4,11,15,24,6.303}
> In[2]:= $Version
> Out[2]= 7.0 for Microsoft Windows (64-bit) (November 11, 2008)
>
> Even if Mathematica failed here since Mathematica supports Regular
> Expressions there are many regex libraries for date time validation and
> groupings
>
> see  
> http://regexlib.com/DisplayPatterns.aspx?cattabindex=4&categoryid=5&p=2
>
> Michael Ashe stuff is well described. You may need to include the
> milliseconds parts.
>
> Hans
>
> "graser" <graser at gmail.com> wrote in message
> news:hm322l$m95$1 at smc.vnet.net...
>> On Feb 18, 5:16 am, Bill Rowe <readn... at sbcglobal.net> wrote:
>>> On 2/17/10 at 7:01 AM, gra... at gmail.com (graser) wrote:
>>>
>>> >I have a list of date and time string such as..
>>> >AA = {"Start", "Time", "11/4/2009", "3:24:06.505", "PM"}
>>> >I want to read "11/4/2009", "3:24:06.505", "PM" as date format..
>>> >so I did
>>> >DateList["11/4/2009 3:24:06.505 PM"] and actually it gives me as
>>> >{2009, 11, 4, 15, 24, 6.505}
>>> >But there is also waring message like..
>>> >** DateList::ambig: Warning: the interpretation of the string
>>> >11/4/2009 3:24:06.505 PM as a date is ambiguous. >> ***
>>> >So I thought the problem was "PM"
>>>
>>> That is not the issue. The uncertainty is whether the "11/4"
>>> portion of the string is a month followed by a day or a day
>>> followed by a month.
>>>
>>> >I tried it again with
>>> >DateList[{"11/4/2009 3:24:06.505 PM", {"Day", "Month", "Year",
>>> >"Hour", "Minute", "Second", "AMPM"}}]
>>> >But it didn't work...
>>>
>>> This doesn't work because what you told Mathematica to expect
>>> doesn't match the format of the string. This works
>>>
>>> In[9]:= DateList[{"11/4/2009 3:24:06.505 PM", {"Day", "Month", "Year",
>>>      "Hour", "Minute", "Second", "Millisecond", "AMPM"}}]
>>>
>>> Out[9]= {2009,4,11,3,24,6.505}
>>>
>>> and this works
>>>
>>> In[10]:= DateList[{"11/4/2009 3:24:06 PM", {"Day", "Month", "Year",
>>>     "Hour", "Minute", "Second", "AMPM"}}]
>>>
>>> Out[10]= {2009,4,11,3,24,6}
>>
>> Hello,
>>
>> Thanks for your reply...
>>
>> But my question was
>>
>> 1. how to make Mathematica recognize AMPM situation
>>
>> It is not working with your methods
>>
>> 2. Yes.. how to clear the ambiguity..
>> either day/month or month/day...
>>
>
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: Re: Re: does it make sense ?
  • Next by Date: Pass argument name to plot label
  • Previous by thread: Re: Date & Time format..
  • Next by thread: Arctangent approximation