Date Time function in Dialogflow fulfillment





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







2















Can anyone explain what does these function means?



setDate = agent.parameters.date.split('T')[0];
setTime = agent.parameters.time.split('T')[1].split(':')[0];


I am doing a booking for reservation and I want Google Assistant to print out the timing user enter as a 12-hour Format. Right now, when I key in 4pm, it will print out at 16. My date it working perfectly, but the time is not. I've tried other methods, but I don't really understand that the "split" means.



eg. If I say "book table today 4.30pm", then google will reply as "You have booked on 2018-11-23 at 4:30PM." But with the codes now, it prints out " 2018-11-23 at 16"



This is my code:



function makeBooking(agent){

bookingDate= agent.parameters.date.split('T')[0];
bookingTime = agent.parameters.time.split('T')[1].split(':')[0];

agent.add(`You have booked on ${availDate} at ${availTime}.`);

}

// A helper function that receives Dialogflow's 'date' and 'time' parameters and creates a Date instance.

function convertParametersDate(date, time){
var resultDate = new Date(Date.parse(date.split('T')[0]));
return resultDate;
}









share|improve this question

























  • it would be easier to explain if you provided the format of date and time. What .split() does is divide a string into array elements using the parameter to determine where to split. So a string like "XXXX-XX-XXTYY:YY:YY:YY" split with .split('T') would result in an array of ["XXXX-XX-XX", "YY:YY:YY:YY"].

    – Randy Casburn
    Nov 23 '18 at 2:14













  • @RandyCasburn Hi, I've edited my code above, the format is stated as above.

    – ALABADAMA
    Nov 23 '18 at 2:28











  • Date.parse is redundant in new Date(Date.parse(date.split('T')[0])), you can use new Date(date.split('T')[0]). Anyway, it seems it should be new Date(date + 'T' + time).

    – RobG
    Nov 23 '18 at 2:34













  • @RandyCasburn thanks, but it still prints as the 24hour format.

    – ALABADAMA
    Nov 23 '18 at 2:39






  • 1





    It's impossible to answer your question until you provide the format of the value returned by agent.parameters.date. The code infers ISO 8601 extended formatting, but the result indicates otherwise.

    – RobG
    Nov 23 '18 at 2:42




















2















Can anyone explain what does these function means?



setDate = agent.parameters.date.split('T')[0];
setTime = agent.parameters.time.split('T')[1].split(':')[0];


I am doing a booking for reservation and I want Google Assistant to print out the timing user enter as a 12-hour Format. Right now, when I key in 4pm, it will print out at 16. My date it working perfectly, but the time is not. I've tried other methods, but I don't really understand that the "split" means.



eg. If I say "book table today 4.30pm", then google will reply as "You have booked on 2018-11-23 at 4:30PM." But with the codes now, it prints out " 2018-11-23 at 16"



This is my code:



function makeBooking(agent){

bookingDate= agent.parameters.date.split('T')[0];
bookingTime = agent.parameters.time.split('T')[1].split(':')[0];

agent.add(`You have booked on ${availDate} at ${availTime}.`);

}

// A helper function that receives Dialogflow's 'date' and 'time' parameters and creates a Date instance.

function convertParametersDate(date, time){
var resultDate = new Date(Date.parse(date.split('T')[0]));
return resultDate;
}









share|improve this question

























  • it would be easier to explain if you provided the format of date and time. What .split() does is divide a string into array elements using the parameter to determine where to split. So a string like "XXXX-XX-XXTYY:YY:YY:YY" split with .split('T') would result in an array of ["XXXX-XX-XX", "YY:YY:YY:YY"].

    – Randy Casburn
    Nov 23 '18 at 2:14













  • @RandyCasburn Hi, I've edited my code above, the format is stated as above.

    – ALABADAMA
    Nov 23 '18 at 2:28











  • Date.parse is redundant in new Date(Date.parse(date.split('T')[0])), you can use new Date(date.split('T')[0]). Anyway, it seems it should be new Date(date + 'T' + time).

    – RobG
    Nov 23 '18 at 2:34













  • @RandyCasburn thanks, but it still prints as the 24hour format.

    – ALABADAMA
    Nov 23 '18 at 2:39






  • 1





    It's impossible to answer your question until you provide the format of the value returned by agent.parameters.date. The code infers ISO 8601 extended formatting, but the result indicates otherwise.

    – RobG
    Nov 23 '18 at 2:42
















2












2








2


1






Can anyone explain what does these function means?



setDate = agent.parameters.date.split('T')[0];
setTime = agent.parameters.time.split('T')[1].split(':')[0];


I am doing a booking for reservation and I want Google Assistant to print out the timing user enter as a 12-hour Format. Right now, when I key in 4pm, it will print out at 16. My date it working perfectly, but the time is not. I've tried other methods, but I don't really understand that the "split" means.



eg. If I say "book table today 4.30pm", then google will reply as "You have booked on 2018-11-23 at 4:30PM." But with the codes now, it prints out " 2018-11-23 at 16"



This is my code:



function makeBooking(agent){

bookingDate= agent.parameters.date.split('T')[0];
bookingTime = agent.parameters.time.split('T')[1].split(':')[0];

agent.add(`You have booked on ${availDate} at ${availTime}.`);

}

// A helper function that receives Dialogflow's 'date' and 'time' parameters and creates a Date instance.

function convertParametersDate(date, time){
var resultDate = new Date(Date.parse(date.split('T')[0]));
return resultDate;
}









share|improve this question
















Can anyone explain what does these function means?



setDate = agent.parameters.date.split('T')[0];
setTime = agent.parameters.time.split('T')[1].split(':')[0];


I am doing a booking for reservation and I want Google Assistant to print out the timing user enter as a 12-hour Format. Right now, when I key in 4pm, it will print out at 16. My date it working perfectly, but the time is not. I've tried other methods, but I don't really understand that the "split" means.



eg. If I say "book table today 4.30pm", then google will reply as "You have booked on 2018-11-23 at 4:30PM." But with the codes now, it prints out " 2018-11-23 at 16"



This is my code:



function makeBooking(agent){

bookingDate= agent.parameters.date.split('T')[0];
bookingTime = agent.parameters.time.split('T')[1].split(':')[0];

agent.add(`You have booked on ${availDate} at ${availTime}.`);

}

// A helper function that receives Dialogflow's 'date' and 'time' parameters and creates a Date instance.

function convertParametersDate(date, time){
var resultDate = new Date(Date.parse(date.split('T')[0]));
return resultDate;
}






javascript dialogflow actions-on-google






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 2:36







ALABADAMA

















asked Nov 23 '18 at 2:06









ALABADAMAALABADAMA

507




507













  • it would be easier to explain if you provided the format of date and time. What .split() does is divide a string into array elements using the parameter to determine where to split. So a string like "XXXX-XX-XXTYY:YY:YY:YY" split with .split('T') would result in an array of ["XXXX-XX-XX", "YY:YY:YY:YY"].

    – Randy Casburn
    Nov 23 '18 at 2:14













  • @RandyCasburn Hi, I've edited my code above, the format is stated as above.

    – ALABADAMA
    Nov 23 '18 at 2:28











  • Date.parse is redundant in new Date(Date.parse(date.split('T')[0])), you can use new Date(date.split('T')[0]). Anyway, it seems it should be new Date(date + 'T' + time).

    – RobG
    Nov 23 '18 at 2:34













  • @RandyCasburn thanks, but it still prints as the 24hour format.

    – ALABADAMA
    Nov 23 '18 at 2:39






  • 1





    It's impossible to answer your question until you provide the format of the value returned by agent.parameters.date. The code infers ISO 8601 extended formatting, but the result indicates otherwise.

    – RobG
    Nov 23 '18 at 2:42





















  • it would be easier to explain if you provided the format of date and time. What .split() does is divide a string into array elements using the parameter to determine where to split. So a string like "XXXX-XX-XXTYY:YY:YY:YY" split with .split('T') would result in an array of ["XXXX-XX-XX", "YY:YY:YY:YY"].

    – Randy Casburn
    Nov 23 '18 at 2:14













  • @RandyCasburn Hi, I've edited my code above, the format is stated as above.

    – ALABADAMA
    Nov 23 '18 at 2:28











  • Date.parse is redundant in new Date(Date.parse(date.split('T')[0])), you can use new Date(date.split('T')[0]). Anyway, it seems it should be new Date(date + 'T' + time).

    – RobG
    Nov 23 '18 at 2:34













  • @RandyCasburn thanks, but it still prints as the 24hour format.

    – ALABADAMA
    Nov 23 '18 at 2:39






  • 1





    It's impossible to answer your question until you provide the format of the value returned by agent.parameters.date. The code infers ISO 8601 extended formatting, but the result indicates otherwise.

    – RobG
    Nov 23 '18 at 2:42



















it would be easier to explain if you provided the format of date and time. What .split() does is divide a string into array elements using the parameter to determine where to split. So a string like "XXXX-XX-XXTYY:YY:YY:YY" split with .split('T') would result in an array of ["XXXX-XX-XX", "YY:YY:YY:YY"].

– Randy Casburn
Nov 23 '18 at 2:14







it would be easier to explain if you provided the format of date and time. What .split() does is divide a string into array elements using the parameter to determine where to split. So a string like "XXXX-XX-XXTYY:YY:YY:YY" split with .split('T') would result in an array of ["XXXX-XX-XX", "YY:YY:YY:YY"].

– Randy Casburn
Nov 23 '18 at 2:14















@RandyCasburn Hi, I've edited my code above, the format is stated as above.

– ALABADAMA
Nov 23 '18 at 2:28





@RandyCasburn Hi, I've edited my code above, the format is stated as above.

– ALABADAMA
Nov 23 '18 at 2:28













Date.parse is redundant in new Date(Date.parse(date.split('T')[0])), you can use new Date(date.split('T')[0]). Anyway, it seems it should be new Date(date + 'T' + time).

– RobG
Nov 23 '18 at 2:34







Date.parse is redundant in new Date(Date.parse(date.split('T')[0])), you can use new Date(date.split('T')[0]). Anyway, it seems it should be new Date(date + 'T' + time).

– RobG
Nov 23 '18 at 2:34















@RandyCasburn thanks, but it still prints as the 24hour format.

– ALABADAMA
Nov 23 '18 at 2:39





@RandyCasburn thanks, but it still prints as the 24hour format.

– ALABADAMA
Nov 23 '18 at 2:39




1




1





It's impossible to answer your question until you provide the format of the value returned by agent.parameters.date. The code infers ISO 8601 extended formatting, but the result indicates otherwise.

– RobG
Nov 23 '18 at 2:42







It's impossible to answer your question until you provide the format of the value returned by agent.parameters.date. The code infers ISO 8601 extended formatting, but the result indicates otherwise.

– RobG
Nov 23 '18 at 2:42














2 Answers
2






active

oldest

votes


















1














According to the dialoflow documentation, sys.date returns a date string in ISO 8601 format like "2018-04-06T12:00:00-06:00".



So if agent.parameters.date is a string in the same format, then in the makeBooking function, assuming the value is "2018-11-23T16:51:42+05:30" then:



function makeBooking(agent){ 
// 2018-11-23
var bookingDate= agent.parameters.date.split('T')[0];
// 16
var bookingTime = agent.parameters.time.split('T')[1].split(':')[0];
// You have booked on 2018-11-23 at 16
agent.add(`You have booked on ${availDate} at ${availTime}.`);
}


If you want the time to be "4:51 pm" instead, then you need to convert "16:51" to an appropriate format. There are many, many questions here already on reformatting date strings, in this case you want the date and time as separate strings, so you might use something like the following that returns an array of the date and time as separate elements:






// "2018-11-23T16:51:42+05:30"
function reformatDate(s) {
// ["2018-11-23", "16:51:42+05:30"]
var b = s.split('T');
// ["16", "51"]
var t = b[1].slice(0,5).split(':');
return [b[0], `${t[0]%12||12}:${t[1]} ${t[0]<12?'am':'pm'}`];
}

["2018-11-23T16:51:42+05:30",
"2018-11-23T06:16:42+05:30",
"2018-11-23T00:01:42+05:30",
"2018-11-23T23:55:42+05:30"
].forEach(s => {
var parts = reformatDate(s);
console.log(`You have booked on ${parts[0]} at ${parts[1]}`);
});








share|improve this answer































    0














    Dialogflow's @sys.time parameter returns time in YYYY-MM-DDTHH:MM:SS+05:30 format where +05:30 is the time offset of India and it will vary from country to country.



    When you say book table today 4.30pm, parameters extracted will be :




    parameters': {'time': '2018-11-23T16:30:00+05:30', 'date.original':
    'today', 'time.original': '4:30 pm', 'date':
    '2018-11-23T12:00:00+05:30'
    }




    split() function will split the string into multiple parts based on the delimiter you provide.



    Below pic will help you understand what's happening with you function .split('T')[1].split(':')[0]



    enter image description here



    Below code should work better in your case:



    from datetime import datetime
    setTime = agent.parameters.time.split('T')[1].split('+')[0]
    setTime = datetime.strptime(setTime, '%H:%m:%S')
    setTime = setTime.strftime('%I:%M %p')


    this will give 04:30 PM



    Hope it helps.






    share|improve this answer
























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439863%2fdate-time-function-in-dialogflow-fulfillment%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      According to the dialoflow documentation, sys.date returns a date string in ISO 8601 format like "2018-04-06T12:00:00-06:00".



      So if agent.parameters.date is a string in the same format, then in the makeBooking function, assuming the value is "2018-11-23T16:51:42+05:30" then:



      function makeBooking(agent){ 
      // 2018-11-23
      var bookingDate= agent.parameters.date.split('T')[0];
      // 16
      var bookingTime = agent.parameters.time.split('T')[1].split(':')[0];
      // You have booked on 2018-11-23 at 16
      agent.add(`You have booked on ${availDate} at ${availTime}.`);
      }


      If you want the time to be "4:51 pm" instead, then you need to convert "16:51" to an appropriate format. There are many, many questions here already on reformatting date strings, in this case you want the date and time as separate strings, so you might use something like the following that returns an array of the date and time as separate elements:






      // "2018-11-23T16:51:42+05:30"
      function reformatDate(s) {
      // ["2018-11-23", "16:51:42+05:30"]
      var b = s.split('T');
      // ["16", "51"]
      var t = b[1].slice(0,5).split(':');
      return [b[0], `${t[0]%12||12}:${t[1]} ${t[0]<12?'am':'pm'}`];
      }

      ["2018-11-23T16:51:42+05:30",
      "2018-11-23T06:16:42+05:30",
      "2018-11-23T00:01:42+05:30",
      "2018-11-23T23:55:42+05:30"
      ].forEach(s => {
      var parts = reformatDate(s);
      console.log(`You have booked on ${parts[0]} at ${parts[1]}`);
      });








      share|improve this answer




























        1














        According to the dialoflow documentation, sys.date returns a date string in ISO 8601 format like "2018-04-06T12:00:00-06:00".



        So if agent.parameters.date is a string in the same format, then in the makeBooking function, assuming the value is "2018-11-23T16:51:42+05:30" then:



        function makeBooking(agent){ 
        // 2018-11-23
        var bookingDate= agent.parameters.date.split('T')[0];
        // 16
        var bookingTime = agent.parameters.time.split('T')[1].split(':')[0];
        // You have booked on 2018-11-23 at 16
        agent.add(`You have booked on ${availDate} at ${availTime}.`);
        }


        If you want the time to be "4:51 pm" instead, then you need to convert "16:51" to an appropriate format. There are many, many questions here already on reformatting date strings, in this case you want the date and time as separate strings, so you might use something like the following that returns an array of the date and time as separate elements:






        // "2018-11-23T16:51:42+05:30"
        function reformatDate(s) {
        // ["2018-11-23", "16:51:42+05:30"]
        var b = s.split('T');
        // ["16", "51"]
        var t = b[1].slice(0,5).split(':');
        return [b[0], `${t[0]%12||12}:${t[1]} ${t[0]<12?'am':'pm'}`];
        }

        ["2018-11-23T16:51:42+05:30",
        "2018-11-23T06:16:42+05:30",
        "2018-11-23T00:01:42+05:30",
        "2018-11-23T23:55:42+05:30"
        ].forEach(s => {
        var parts = reformatDate(s);
        console.log(`You have booked on ${parts[0]} at ${parts[1]}`);
        });








        share|improve this answer


























          1












          1








          1







          According to the dialoflow documentation, sys.date returns a date string in ISO 8601 format like "2018-04-06T12:00:00-06:00".



          So if agent.parameters.date is a string in the same format, then in the makeBooking function, assuming the value is "2018-11-23T16:51:42+05:30" then:



          function makeBooking(agent){ 
          // 2018-11-23
          var bookingDate= agent.parameters.date.split('T')[0];
          // 16
          var bookingTime = agent.parameters.time.split('T')[1].split(':')[0];
          // You have booked on 2018-11-23 at 16
          agent.add(`You have booked on ${availDate} at ${availTime}.`);
          }


          If you want the time to be "4:51 pm" instead, then you need to convert "16:51" to an appropriate format. There are many, many questions here already on reformatting date strings, in this case you want the date and time as separate strings, so you might use something like the following that returns an array of the date and time as separate elements:






          // "2018-11-23T16:51:42+05:30"
          function reformatDate(s) {
          // ["2018-11-23", "16:51:42+05:30"]
          var b = s.split('T');
          // ["16", "51"]
          var t = b[1].slice(0,5).split(':');
          return [b[0], `${t[0]%12||12}:${t[1]} ${t[0]<12?'am':'pm'}`];
          }

          ["2018-11-23T16:51:42+05:30",
          "2018-11-23T06:16:42+05:30",
          "2018-11-23T00:01:42+05:30",
          "2018-11-23T23:55:42+05:30"
          ].forEach(s => {
          var parts = reformatDate(s);
          console.log(`You have booked on ${parts[0]} at ${parts[1]}`);
          });








          share|improve this answer













          According to the dialoflow documentation, sys.date returns a date string in ISO 8601 format like "2018-04-06T12:00:00-06:00".



          So if agent.parameters.date is a string in the same format, then in the makeBooking function, assuming the value is "2018-11-23T16:51:42+05:30" then:



          function makeBooking(agent){ 
          // 2018-11-23
          var bookingDate= agent.parameters.date.split('T')[0];
          // 16
          var bookingTime = agent.parameters.time.split('T')[1].split(':')[0];
          // You have booked on 2018-11-23 at 16
          agent.add(`You have booked on ${availDate} at ${availTime}.`);
          }


          If you want the time to be "4:51 pm" instead, then you need to convert "16:51" to an appropriate format. There are many, many questions here already on reformatting date strings, in this case you want the date and time as separate strings, so you might use something like the following that returns an array of the date and time as separate elements:






          // "2018-11-23T16:51:42+05:30"
          function reformatDate(s) {
          // ["2018-11-23", "16:51:42+05:30"]
          var b = s.split('T');
          // ["16", "51"]
          var t = b[1].slice(0,5).split(':');
          return [b[0], `${t[0]%12||12}:${t[1]} ${t[0]<12?'am':'pm'}`];
          }

          ["2018-11-23T16:51:42+05:30",
          "2018-11-23T06:16:42+05:30",
          "2018-11-23T00:01:42+05:30",
          "2018-11-23T23:55:42+05:30"
          ].forEach(s => {
          var parts = reformatDate(s);
          console.log(`You have booked on ${parts[0]} at ${parts[1]}`);
          });








          // "2018-11-23T16:51:42+05:30"
          function reformatDate(s) {
          // ["2018-11-23", "16:51:42+05:30"]
          var b = s.split('T');
          // ["16", "51"]
          var t = b[1].slice(0,5).split(':');
          return [b[0], `${t[0]%12||12}:${t[1]} ${t[0]<12?'am':'pm'}`];
          }

          ["2018-11-23T16:51:42+05:30",
          "2018-11-23T06:16:42+05:30",
          "2018-11-23T00:01:42+05:30",
          "2018-11-23T23:55:42+05:30"
          ].forEach(s => {
          var parts = reformatDate(s);
          console.log(`You have booked on ${parts[0]} at ${parts[1]}`);
          });





          // "2018-11-23T16:51:42+05:30"
          function reformatDate(s) {
          // ["2018-11-23", "16:51:42+05:30"]
          var b = s.split('T');
          // ["16", "51"]
          var t = b[1].slice(0,5).split(':');
          return [b[0], `${t[0]%12||12}:${t[1]} ${t[0]<12?'am':'pm'}`];
          }

          ["2018-11-23T16:51:42+05:30",
          "2018-11-23T06:16:42+05:30",
          "2018-11-23T00:01:42+05:30",
          "2018-11-23T23:55:42+05:30"
          ].forEach(s => {
          var parts = reformatDate(s);
          console.log(`You have booked on ${parts[0]} at ${parts[1]}`);
          });






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 6:34









          RobGRobG

          100k19112148




          100k19112148

























              0














              Dialogflow's @sys.time parameter returns time in YYYY-MM-DDTHH:MM:SS+05:30 format where +05:30 is the time offset of India and it will vary from country to country.



              When you say book table today 4.30pm, parameters extracted will be :




              parameters': {'time': '2018-11-23T16:30:00+05:30', 'date.original':
              'today', 'time.original': '4:30 pm', 'date':
              '2018-11-23T12:00:00+05:30'
              }




              split() function will split the string into multiple parts based on the delimiter you provide.



              Below pic will help you understand what's happening with you function .split('T')[1].split(':')[0]



              enter image description here



              Below code should work better in your case:



              from datetime import datetime
              setTime = agent.parameters.time.split('T')[1].split('+')[0]
              setTime = datetime.strptime(setTime, '%H:%m:%S')
              setTime = setTime.strftime('%I:%M %p')


              this will give 04:30 PM



              Hope it helps.






              share|improve this answer




























                0














                Dialogflow's @sys.time parameter returns time in YYYY-MM-DDTHH:MM:SS+05:30 format where +05:30 is the time offset of India and it will vary from country to country.



                When you say book table today 4.30pm, parameters extracted will be :




                parameters': {'time': '2018-11-23T16:30:00+05:30', 'date.original':
                'today', 'time.original': '4:30 pm', 'date':
                '2018-11-23T12:00:00+05:30'
                }




                split() function will split the string into multiple parts based on the delimiter you provide.



                Below pic will help you understand what's happening with you function .split('T')[1].split(':')[0]



                enter image description here



                Below code should work better in your case:



                from datetime import datetime
                setTime = agent.parameters.time.split('T')[1].split('+')[0]
                setTime = datetime.strptime(setTime, '%H:%m:%S')
                setTime = setTime.strftime('%I:%M %p')


                this will give 04:30 PM



                Hope it helps.






                share|improve this answer


























                  0












                  0








                  0







                  Dialogflow's @sys.time parameter returns time in YYYY-MM-DDTHH:MM:SS+05:30 format where +05:30 is the time offset of India and it will vary from country to country.



                  When you say book table today 4.30pm, parameters extracted will be :




                  parameters': {'time': '2018-11-23T16:30:00+05:30', 'date.original':
                  'today', 'time.original': '4:30 pm', 'date':
                  '2018-11-23T12:00:00+05:30'
                  }




                  split() function will split the string into multiple parts based on the delimiter you provide.



                  Below pic will help you understand what's happening with you function .split('T')[1].split(':')[0]



                  enter image description here



                  Below code should work better in your case:



                  from datetime import datetime
                  setTime = agent.parameters.time.split('T')[1].split('+')[0]
                  setTime = datetime.strptime(setTime, '%H:%m:%S')
                  setTime = setTime.strftime('%I:%M %p')


                  this will give 04:30 PM



                  Hope it helps.






                  share|improve this answer













                  Dialogflow's @sys.time parameter returns time in YYYY-MM-DDTHH:MM:SS+05:30 format where +05:30 is the time offset of India and it will vary from country to country.



                  When you say book table today 4.30pm, parameters extracted will be :




                  parameters': {'time': '2018-11-23T16:30:00+05:30', 'date.original':
                  'today', 'time.original': '4:30 pm', 'date':
                  '2018-11-23T12:00:00+05:30'
                  }




                  split() function will split the string into multiple parts based on the delimiter you provide.



                  Below pic will help you understand what's happening with you function .split('T')[1].split(':')[0]



                  enter image description here



                  Below code should work better in your case:



                  from datetime import datetime
                  setTime = agent.parameters.time.split('T')[1].split('+')[0]
                  setTime = datetime.strptime(setTime, '%H:%m:%S')
                  setTime = setTime.strftime('%I:%M %p')


                  this will give 04:30 PM



                  Hope it helps.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 23 '18 at 6:40









                  sid8491sid8491

                  3,65431338




                  3,65431338






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439863%2fdate-time-function-in-dialogflow-fulfillment%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

                      How to change which sound is reproduced for terminal bell?

                      Can I use Tabulator js library in my java Spring + Thymeleaf project?