Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8792387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:58:20+00:00 2026-06-13T22:58:20+00:00

The $model->datetime is d-m-Y H:i:s . <?php echo $form->textField($model,’datetime’); ?> I would like the

  • 0

The $model->datetime is d-m-Y H:i:s.

<?php echo $form->textField($model,'datetime'); ?>

I would like the value of the input just be d-m-Y, how can I format it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:58:20+00:00Added an answer on June 13, 2026 at 10:58 pm

    One option would be to convert the date to a human readable format to display it, and then back to the format needed by the database before you save. You could edit/create the afterFind() method in your model to convert the date to a human readable format, something like so:

    public function afterFind()
    {
        $newDate = DateTime::createFromFormat('d-m-Y H:i:s', $this->datetime);
        $this->datetime = $newDate->format('d-m-Y');
    
        return parent::afterFind();
    }
    

    And again before you save by editing/creating your model’s beforeSave() method, for example something like:

    public function beforeSave()
    {
        $newDate = DateTime::createFromFormat('d-m-Y', $this->datetime);
        $this->datetime = $newDate->format('d-m-Y H:i:s');
    
        return parent::beforeSave();
    }
    

    Note that when you save, the hour, minute and second will always be 0 in the examples above. You’d also need to put some validation to make sure your user input was in the correct d-m-Y format too, or the date conversion won’t work.

    *Fixed typo newdate->newDate

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to write my own model binder for DateTime type. First of
I have an input form for date input.I have used Datetime Picker for input
I have the following editor template @model DateTime? @Html.TextBox(, (Model.HasValue ? Model.Value.ToShortDateString() : string.Empty),
I have in my view Datetime fied like these @Html.EditorFor(m => m.StartDate) <input type=button
echo $this->Form->create('Comment', array('url'=>array('controller' => 'comments', 'action' =>'add', $listposts['Post']['id']) ) ); echo $this->Form->input('post_id',array('type'=>'hidden','style'=>'width:30%','value'=>$listposts['Post']['id'])); echo $this->Form->input('name',array('style'=>'width:30%'));
Problems with wiring up datepicker The code for partial view @model System.DateTime @Html.TextBox(, Model.ToString(dd/MM/yy),
my Project model has 2 datetime atttributes: start_date and end_date. Now I want all
I have a model with a datetime field: class MyModel(models.Model): created = models.DateTimeField(auto_now =
Currently I have a DateTime property for a model. I am using the telerik
I have a model Coupon with an attribute expired_at , of class DateTime and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.