my input will be from a variable (Ticket.CreationDate) and will look like
2/4/2011 9:34:48 AM (it will vary of course)
Ideally I could pass in the variable as-is and get the different results
like
unknownDateFunc(Ticket.DateCreation) \ Outputs= Friday, February 4, 2011
unknownTimeFunc(Ticket.DateCreation) \ Outputs= 9:34 AM
Meddling with Date.parse() and .toDateString()
and I just can’t figure it out.
Resolved : using Steve Levithan Method
var datevar = dateFormat(TicketList.Tickets[Ticket].CreationDate.split(" ", 1), "fullDate");
// without .split(" ",1) it displayed as "Thu, Feb 24, 2011 00:00" I don't know why
var timevar = dateFormat(TicketList.Tickets[Ticket].CreationDate, "shortTime");
I would suggest a combination of 2 different Date libraries I am aware of.
The first, for parsing the date from a string, is DateJS. You can find it at http://www.datejs.com/. Your example parses with their library fine (once you include appropriate quote marks)
The other library is for creating nicely formatted string values based on your date object. This can be found at http://blog.stevenlevithan.com/archives/date-time-format. For example, from that page:
The fact that you have a static format makes a solution simple.
Create a function which takes date and in-format string and out-format string as parameter
You can get different format string from here