1

I have a content type with a date field. It is setup to collect an end date (optional). The field type is Date (UNIX timestamp).

The field is to store "experience" as (from) January 2011 - (to) March 2012.

If I don't check the "show end date" when creating content, the end date is the same than the start date. But in my case, I sometimes need to collect an end date that would be the same than the start date (January 2011 - January 2011).

So how do I know if that "show end date" checkbox was checked?

Right now here is what I get when the end date is the same than the start date:

value (String, 10 characters ) 1443650400
value2 (String, 10 characters ) 1443650400

And this is what I get when the "show end date" was not checked:

value (String, 10 characters ) 1443650400
value2 (String, 10 characters ) 1443650400
2

I'm going to take a guess and assume you have the end-date defaulting to the start-date in the Date field, field-settings?

enter image description here

That way if they click the checkbox for Show End Date, they have to provide a value for it. otherwise it will be empty; essentially letting you know if the checkbox was checked or not.

  • That sounded like a good catch and it was set on "Same as start date". So I changed it to "No default value" but the same still happens. Btw, the field is used in a field collection. Don't know if this can make any difference but it might be worth mentioning. – MrUpsidown Oct 5 '15 at 16:12
  • Another thing I just noticed with using it in a field collection: whenever I tick that "Show end date" option for a field, then save my node, it will go back to that option not being checked - but still, an end date is saved. Strange! – MrUpsidown Oct 5 '15 at 16:19
  • Make sure to update the node you are testing, happens to me sometimes. I'll look more into it this morning. If by default the value is staying the same regardless of the action then maybe, the checkbox just allows the user to edit the value, and that is a default value set, which means you might have to hook into something. Alternatively you can give two date fields one for start and end, that way the end will always be empty if nothing is provided. You do loose some out-of-box functionality like showing the date from start to finish on calendar module, ect, nothing too crucial. – DMAC Oct 5 '15 at 16:20
  • Yes, I deleted the different entries from the node, updated the field settings, then added new entries. – MrUpsidown Oct 5 '15 at 16:23
  • I think it's acceptable to check if value1 == value2 to determine if it's not been checked. If the start date is literally the same as end date then whats the point of the end date data? it's useless. If there is a Start Date = 10/05/15 - 3:40:55PM and a End Date = 10/05/15 - 3:40:55PM Then I can assume the user didn't select an end date. If the values are different (same day different time) then you know the person selected a end date. If they clicked the box then chose nothing, that's a user entry issue. – DMAC Oct 5 '15 at 16:34

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.