We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Custom date format for date field?

Development and Programming

lebisol's avatar
lebisol
2,234 posts
16 years ago
lebisol's avatar lebisol

Is it possible to adjust the format date in entered for custom field of “date”. Currently the calendar pop-up is great but it always enters hrs values along with date. 2010-02-15 7:31 PM vs. desired just the date 2010-02-15 Anything that can ‘hacked up’ on front end or it pretty much the field definition on mysql side? Thank you!

       
Greg Salt's avatar
Greg Salt
3,988 posts
16 years ago
Greg Salt's avatar Greg Salt

Hi Lebisol,

There is no way to change the format for the built in Date field type. You would have to create a new field type based on the existing one. If you do this you’ll see that the displayed format is specified in system/expressionengine/fieldtypes/ft.date.php on or about line 105.

Cheers

Greg

       
lebisol's avatar
lebisol
2,234 posts
16 years ago
lebisol's avatar lebisol

Thanks Greg, Yes this is a new custom field….not much of a CI guy so any specifics to what to change in ft.date.php? I have tried it as:

$cal_date = ( ! $data) ? $this->EE->localize->set_localized_time() * 1000 );

but not luck just some php errors. Thanks!

       
Ingmar's avatar
Ingmar
29,245 posts
16 years ago
Ingmar's avatar Ingmar

Let me move this thread for you, lebisol…

       
Reusser Design, LLC's avatar
Reusser Design, LLC
58 posts
16 years ago
Reusser Design, LLC's avatar Reusser Design, LLC

I was able to create a new fieldtype that sports the Date field and removes the time output. This is my first attempt at anything like this and I cannot completely guarantee its perfection by any stretch of the imagination. But it could be a start!

Right now it sets the date as “Fixed” and removes the drop down for “Localization” or “Fixed”. I also have this set to output JUST the date and no time.

Hope it helps!

       
lebisol's avatar
lebisol
2,234 posts
16 years ago
lebisol's avatar lebisol

I am getting an error of:

Fatal error: Class name must be a valid object or a string in 
.../system/expressionengine/libraries/api/Api_channel_fields.php  on line 217

I am assuming the idea was just to overwrite the ft.date.php file right?

       
Reusser Design, LLC's avatar
Reusser Design, LLC
58 posts
16 years ago
Reusser Design, LLC's avatar Reusser Design, LLC

Lebisol,

Sorry, I should have clarified. This was NOT intended to replace the date fieldtype. It was intended to add another fieldtype. I should have tested this in a third_party folder and sent it that way to clarify.

       
lebisol's avatar
lebisol
2,234 posts
16 years ago
lebisol's avatar lebisol

Ah got it. Nice work so far as it does work on CP side but here is a few things I noticed: - in CP it shows up as ‘Textarea’ for FieldType - in template the custom field does not show up at all

{mydate}
{mydate format="%F %d %Y"}

Thanks Reusser and no pressure on this I am just reporting back.

       
Reusser Design, LLC's avatar
Reusser Design, LLC
58 posts
16 years ago
Reusser Design, LLC's avatar Reusser Design, LLC

Thanks! I should’ve mentioned that I did not test it on the frontend, I just peeked at the information in the database. 😊 It came up with the date and no time and I just made an assumption that it came out correctly on the frontend side of things.

Unfortunately I am not too versed in CI so perhaps someone else could take a stab at it? I’m with you though. I pine for a better date/time field and interaction with EE entries. I’d love to see a date field with just the date, a time field for inputting time separately, and the ability to use those fields as the “entry” and “expiration” date.

I think from a client perspective it is easy to misinterpret what the entry and expiration fields could mean.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.