JS/AS Date Functions

A few date manipulation functions for JS/AS… Convert a MySQL DATE or DATETIME field into a valid JS/AS Date object:

UPDATE: Apparently FireFox can’t handle dashes when parsing the date. In the above replacement, use slashes instead:

Convert a JS Date Object to a MySQL formatted string

Get amount of time between […]

JS/AS Date Object from MySQL DATE or DATETIME

The ECMAScript Date object accepts a string that it pretty generously tries to convert to a valid date. However, DATE and DATETIME returns from MySQL are formatted Y-M-D, which will cause new Date(str) or Date.parse(str) to barf. The quick fix is just to use a simple RegExp to move the year to the 3rd position. […]