Jump to content

Zeros in Datetime Field


antonio
 Share

Recommended Posts

I'd like to be able to have zero's in my datetime field, ie: "2011-01-00" or even "2010-00-00".

At the moment Processwire seems to convert 2011-01-00 into 2010-12-31.

I do not care about the jQuery datepicker.

I'm looking into FieldtypeDatetime.module at the moment but thought maybe someone would have a ready answer... :)

Link to comment
Share on other sites

Hi apeisa!

Yes, that's it.

Most "objects" date has been fully identified, some not.

Using an exceptional standard for those, like the "first of the month if day is unknown", is not satisfying.

Would you suggest a better workaround?

MySql allows me to do this but Processwire seems to process this data.

Link to comment
Share on other sites

Ok, I hacked FieldtypeDatetime.module and InputfieldDatetime.module.

The issue is that, although MySql allows incomplete dates ("1980-00-00"), php's date() does not and ProcessWire obviously uses it for sanitation and formatting of the data.

It now lost some flexibility on formatting but is working as I wanted.  :)

Maybe this could be an option in the future...

(corrected grammar)

Link to comment
Share on other sites

Good that you got it working, but there might be better methods than hacking the core file. Ryan, is it possible to overwrite core modules by using /site/modules/ folder? I think that could be nice & clean solution in those situations, where simple core hack would help.

Link to comment
Share on other sites

Good that you got it working, but there might be better methods than hacking the core file. Ryan, is it possible to overwrite core modules by using /site/modules/ folder? I think that could be nice & clean solution in those situations, where simple core hack would help.

Sure, I could do it that way (duplicating and renaming those two modules/classes in the /site/modules/ folder).

I've done it before:

I was cloning the InputfieldSelect and InputfieldSelectMultiple modules and the only extraordinary thing I remember doing was manually adding those new Inputfields to the database so they would appear as an option for the FieldtypePage.

This was the issue I was solving then, it works on my setup but isn't clean enough for public/universal usage.

Link to comment
Share on other sites

Glad you found a solution to this. You are right that the functions we are using in PHP require full dates, so one can't specify zeros for a given part (except time, if you are using that).

If you only need to support a year, I would just use an integer field rather than a date field.

If you only need to support a month and year, then something I've done in the past is to just ask the client to specify "1" for the day, and then we only use the month/year component for output on the site. This has worked well for me at least.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...