date dd/mm/yyyy

date dd/mm/yyyy

rrzavaletarrzavaleta Posts: 78Questions: 52Answers: 2

Hi allan i need , as I can validate the date in dd / mm / yyyy, in the editor. have any method to accomplish this

Answers

  • zzzzzz Posts: 7Questions: 3Answers: 0
    edited March 2015

    Hi, I was yesterday in the same problem as you. I think I have found a "solution" that could help you.

    I had a date in the string format : 26/01/2015 and I needed the dataTable order It, but It had no a good result, It just ordered by the day.

    My idea is to have two parameters, you need the date as you have now, but a numeric date too, I mean in the case 26/01/2015 convert into a String like 20150126. The DataTable will be able to order It in this format correctly.

    In this case you are ordering the column by a numericDate that can't be seen and you are showing the date as you wanted to see It.
    <td >

    <

    p class="noVisible">${myObject.numericDate}

    <

    p> //20150126

    ${myObject.stringDate} // 26/01/2015
    </td>

    I hope It could help you, maybe is not a solution but It can help in some cases.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    If you are using the prebuilt PHP libraries, I would suggest using the dateFormat validator.

    Allan

  • rrzavaletarrzavaleta Posts: 78Questions: 52Answers: 2
    edited March 2015

    hello check a bit and almost got it , I 'm stuck with validation . I hope mepuedas help.

    this is what I did (using Editor)

    I have not been able to validate

     {
                    label:      "Registered date:",
                    name:       "registered_date",
                    type:       "date",
                    def:        function () { return new Date(); },
                    dateFormat: 'd-m-yy'
                    
                }
    
    Field::inst( 'registered_date' )
             ->validator( 'Validate::dateFormat', array(
            "format"  => 'd-m-yy',
            "message" => "Please enter a date in the format dd-mm-yyyy"
        ) )
                ->getFormatter( 'Format::date_sql_to_format', 'd-m-Y' ) 
                ->setFormatter( 'Format::date_format_to_sql', 'd-m-yy' )
        )
    
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Javascript: dateFormat: 'd-m-yy'

    This uses JQuery UI formatting.

    PHP: "format" => 'd-m-yy',

    This uses PHP date() formatting.

    They are not the same unfortunately.

    Allan

  • zodiacszodiacs Posts: 10Questions: 1Answers: 0
    edited May 2015

    Hi,

    I had the same problem like rrzavaleta. I needed date in dd-mm-yy format validated.

    Here is my solution for everyone who is having the same problem.

    My editor field initialisation looks like this :

    label: "Kaufdatum:",
    name: "object.datePurchase_object",
    def: function () { return new Date(); },
    type: "date",
    dateFormat: 'dd-mm-yy',
    dateImage: "css/images/calender.png",
    opts: {
    changeMonth: true,
    changeYear: true
    }
    

    serverside validation :

    Field::inst( 'object.datePurchase_object' )
         ->validator( 'Validate::dateFormat', array(
              "format" => "d-m-Y",
              "message" => "Datum muss das Format 30-01-2015 haben"
           ))
          ->getFormatter( 'Format::date_sql_to_format', 'd-m-Y' )
          ->setFormatter( 'Format::date_format_to_sql', 'd-m-Y' ),
    

    This is working for me. I hop it can help someone.

    Yves

This discussion has been closed.