Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a CPT for events. I need to display future events for people to register, while hiding past events.

What is the easiest date format for both (1) entering date when creating new event and (2) comparing event dates with current date ?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

The date format for entering the date is largely irrelevant. strtotime will convert a lot of different formats to UNIX time. Just make sure your input format makes sense to your users and make sure that your feed strtottime a format that correctly converts to UNIX time. If you are storing data in the *_postmeta table, that is what I'd most likely do since ordinary math works on UNIX time so numeric comparisons work and because most of PHP's builtin date/time functions would require you to convert to UNIX time anyway. Even the MySQL database can work date logic using FROM_UNIXTIME.

That isn't the only option. If you have your own table you could store in one of MySQL date/time formats and the database can work some date logic for you.

If you don't need any complex date logic you can store as YYYYMMDD and the date will sort correctly using ordinary math. That is is the only human date format that does sort correctly using ordinary math. It doesn't work well if you want to pick "all dates in May of any year" or all "January 1st events"-- that sort of thing.

share|improve this answer

I would suggest storing the dates in DATETIME format as in YYYY-MM-DD HH:MM:SS as it would then be easier to use MySQL to compare values.

As for the frontend user interface just convert it to DATETIME format.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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