0

For the past year, we've been storing date-time values into a custom field _date using strtotime(). There are about 100 PHP date-time stamps in our database from over the past year.

I would really like to use a jQuery datepicker for this custom field - to make it more user friendly. However, the datepicker stores date values differently. Even if I use UNIX time, it adds "000" to the end. This creates problems on the front-end retrieving the data and sorting through it accurately.

From what I can see, I have two basic options.

  1. Convert all current _date values to JS values
  2. Write my code on the front end to account for both JS and PHP values.

I'm using the Advanced Custom Fields datepicker. I think the cleanest way to do this would be to update the existing values in the database to JS time-stamps. Is there an easy way to do this? I don't really feel like manually updating > 100 dates.

All values in this custom_field are currently like this:

  • 1375820168 (php in seconds)

I need them to be like this:

  • 1375820168000 (js in milliseconds)

Or this:

  • 20130706 (js yymmdd)
1

ACF using milliseconds is not standard for timestamps, and nor is it useful.

How much accuracy do you need? Bear in mind that converting to something like yyyymmdd will not accommodate timezones.

If you have access to PHPMyAdmin (or similar) and know your way around SQL, running a quick query would probably be the easiest solution, although ACF's milliseconds would annoy me so much I'd reconsider using that plugin.

  • I can do yymmdd but my understanding is it's then a little harder to sort by date. If you want UNIX time, it's milliseconds. I can run a query, but I'm still stuck manually editing each value aren't I? – timshutes Aug 6 '13 at 21:04
  • 1
    @timshutes : Unix Time is by definition measured in seconds. If it is milliseconds it is not Unix Time. if the plugin is saving "unix time" in milliseconds, the plugin is doing it wrong. – s_ha_dum Aug 6 '13 at 21:12
  • @timshutes If you can run a query, you can just update the appropriate field by multiplying the value by 1000 to get the milliseconds. – vancoder Aug 6 '13 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.