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 8140017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:01:18+00:00 2026-06-06T12:01:18+00:00

I display my date in CGridView as: 22.6.2012 22:53 with: array(‘name’ => ‘date’, ‘value’

  • 0

I display my date in CGridView as: “22.6.2012 22:53” with:

array('name' => 'date',
            'value' => date("j.n.Y G:i", strtotime($model->date))
        ),

But in my filter, I need to search in this format (which is in the database) to get results: “2012-06-22 22:53”.

How can I make my filter to work in the format that is displayed in my CGridView? I’ve searched for an answer but haven’t found one, I’ve also tried adding the date function in my model search() for this attribute:

$criteria->compare('date', date("j.n.Y G:i", strtotime($this->date), true);

but then I just get an empty list 🙂

Help would be greatly appreciated.

  • 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-06T12:01:19+00:00Added an answer on June 6, 2026 at 12:01 pm

    compare() makes a sql sentence with the input, so I had to change the input to my wanted format.

    my function:

    function changeDateToDBformat($datum) {
            if (strstr($datum, '.') || strstr($datum, ':')) {
                $formats = array('!j.n', '!j.n.Y', '!j.n.Y H:i', '!n.Y H:i', '!n.Y', '!H:i', '!j.n.Y H', '!n.Y H', '!Y H:i', '!Y H');
                $date = false;
    
                foreach ($formats as $format) {
                    $date = DateTime::createFromFormat($format, $datum);
                    if (!($date === false)) {
                        $izbraniFormat = $format;
                        break;
                    }
                }
    
                if (!$date === false) {
                    $datum1 = $date->format('Y-m-d H:i');
                    $date2 = DateTime::createFromFormat(substr($izbraniFormat, 1, strlen($izbraniFormat)), $datum);
                    $datum2 = $date2->format('Y-m-d H:i');
    
                    $datumcas1 = explode(' ', $datum1);
                    $datumcas2 = explode(' ', $datum2);
    
                    $prvidatum = explode('-', $datumcas1[0]);
                    $drugidatum = explode('-', $datumcas2[0]);
                    $koncniDatum = '';
                    for ($a = 0; $a < sizeof($prvidatum); $a++) {
                        if ($prvidatum[$a] == $drugidatum[$a])
                            $koncniDatum .= '-' . $prvidatum[$a];
                    }
                    $koncniCas = '';
                    $prvicas = explode('-', $datumcas1[1]);
                    $drugicas = explode('-', $datumcas2[1]);
                    for ($a = 0; $a < sizeof($prvicas); $a++) {
                        if ($prvicas[$a] == $drugicas[$a])
                            $koncniCas .= ':' . $prvicas[$a];
                    }
                    $koncniDatum = substr($koncniDatum, 1, strlen($koncniDatum));
                    if (strlen($koncniCas) > 0)
                        $koncniDatum .= ' ' . substr($koncniCas, 1, strlen($koncniCas));
    
                    $datum = $koncniDatum;
                }
            }
            return $datum;
        }
    //translations:
    //izbrani == selected
    //datum == date
    //cas == time
    //koncni == end
    //prvi == first
    //drugi == second
    

    With this, a user can enter date in the format “j.n.Y H:i” and also just portions of this format (j.n, n.Y, Y H:i,…).

    I would like to thank Jon and nickb for help! link

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

Sidebar

Related Questions

I want to display a date/time submitted value much the same way as Stack
I'm trying to display a date. Sample of my viewmodel code is below: [Display(Name
I have the need to display a date in this format: dd/mm/yyyy. This is
I m using a rich:calendar to display Date in my application But some how
I tried to display date picker using xml code. But it did not display
I want to display date time like 01/08/11 , but i write this string
HI, I need to display date as 15th November 2010 in iPhone SDK. How
I want to display date like this in my website Wednesday, March 03, 2010
Hi guys how do i make it display date only. temp.StartDate.Date doesnt work, it
I want to display a date of birth based on the user locale. In

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.