My adventures in the JS API continue!
I'm trying to set a date metadata field for an asset, and although everything's working and looks OK, my JS API metadata doesn't sort properly when combined with metadata set in the backend. I think it might be a problem with the data I'm sending the API for the date, does anyone know the correct format for dates? At the moment my script (simplified) looks like this:
[font=courier new,courier,monospace] var d = new Date();
var metaDate = d.getFullYear() + '/' + ('0' + (d.getMonth()+1)).slice(-2) + '/' + ('0' + d.getDate()).slice(-2) + ' ' + ('0' + d.getHours()).slice(-2) + ':' + ('0' + d.getMinutes()).slice(-2) + ':' + ('0' + d.getSeconds()).slice(-2);
setMetadata(%asset_assetid%, 118952, metaDate);[/font]
This all basically means that I'm firing in dates with a value of (for example) "2012/12/05 15:01:23". Does that look right?
As I said it looks fine in the backend, but doesn't sort properly in listings. If I re-set the metadata in the backend it sorts as expected, thought it still looks the same in the metadata screen.
Any ideas?
Setting date metadata with the JS API
Nearly, but not quite. You want "2012-12-05 15:01:23", and yes, it is that picky. From the behaviour of some of the date code, it seems to be using regex parsing rather than internally storing as a datestamp, hence small changes like that breaking it…
As Matthew suggested, in the format needs to be 'Y-m-d' ('yyyy-mm-dd') as this is how it's stored in the database
Righto! Thanks for that guys:) Have to say the manual on the JS API is a bit lacking when it comes to that kind of stuff, just glad you're around on the forums to help me out!
[quote]
Have to say the manual on the JS API is a bit lacking when it comes to that kind of stuff
[/quote]
I've added the formats for the individual metadata field types in the Javascript API documentation. If you find that any of the other Matrix documentation is lacking, feel free to use the suggestion form on the site to let me know.
Cheers.