Integrations and APIs for Service

Get Involved. Join the Conversation.

Topic

    Seethalakshmi S
    how to store custom text value in date/time custom field
    Topic posted December 13, 2018 by Seethalakshmi SBlue Ribbon: 750+ Points, tagged Connect PHP, Custom Process Models - CPMs 
    59 Views, 7 Comments
    Title:
    how to store custom text value in date/time custom field
    Summary:
    Store custom text value in date/time custom field
    Content:

    Hi All,

    In ROQL I have received date/time in string format. So I converted into date/time in (MM:DD:YYYY HH:MM") format.

    After that, I need to store the converted date/time value in "Date/time" datatype custom field.

    While I am trying to store the converted value in date/time datatype field, I am getting error like "Type Mismatch"

    How to resolve this?

    Thanks,

    Seethalakshmi

    Version:
    Version 18C
    Code Snippet:

    Comment

     

    • Vlad

      Hey Seethalakshmi,

      Try this:

       $time=$incident->CustomFields->c->x_resolution_time=strtotime($new_date);

      • Seethalakshmi S

        Hi Vlad,

        Thanks for the quick response.

        I am getting "Min Value Exceeded error" 

        I have attached screenshot for your reference.

        • Vlad

          Looks like you are not adding a valid date/time value. The key thing here is that you have to pass the value in UNIX timestamp. I am not sure what you set $new_date to prior to the code you pasted, but try this as a test:

          $new_date = strtotime("now");

          Then:

          $incident->CustomFields->c->x_resolution_time=$new_date;

          • Seethalakshmi S

            Hi Vlad,

            In ROQL, I have received date/time  "2018-12-12T09:58:00Z " in this format.

            I have formatted the date/time into "12-12-2018  09:58 PM" by using the below date format, 
            $newDateTime = date(' n-j-Y-h:i A', strtotime($currentDateTime));

            I have attached screenshot for you reference. The result which I stored in "Custom Text Field"

            Here I need to pass the date value into "Date/Time" custom field.

            • Vlad

              incident->CustomFields->c->x_resolution_time = strtotime($currentDateTime);

              incident->CustomFields->c->x_resolution_time = strtotime($newDateTime);

              Both these should work in your case.

              Try echoing strtotime($currentDateTime) and strtotime($newDateTime), make sure they are valid UNIX timestamps (e.g. 1544608680)

              • Seethalakshmi S

                Hi Vlad,

                I am getting UNIX timestamp value.

                How to convert and store the unix timestamp value in date/time custom field? 

    • Suresh Thirukoti

      I too got this error in recent times..I went with the documentation example of using mktime()....check PHP API documentation 

       

      ~Suresh