Get Current Date/time

I am trying to build a connector which needs the call to include the date and time in the header..

 

Date / Time (x-mc-date)

The x-mc-date header must be created in the following format:

Tue, 24 Nov 2015 12:50:11 GMT

 

Any ideas how I can get the current date and time and then also in this format?

 

Thanks

Best Answer

  • eric_tetik
    eric_tetik Member
    Answer ✓

    Here's a little more formatting to get the result you need:

    var options = {
      weekday: 'short',
      year: 'numeric',
      month: 'short',
      day: 'numeric',
      hour: '2-digit',
      minute: '2-digit',
      second: '2-digit',
      hour12: false
    }
    today = new Date();

    var date = today.toLocaleDateString("en-AU", options) + ' GMT';

    // Replace period with nothing
    var date1 = date.replace(".", "");

    // Replace all instances of a comma with nothing
    var date2 = date1.replace(/,/g, "");

    // Re-add the comma after the weekday

    var final = date2.substring(0, 3) + ', ' + date2.substring(4);

     

    console.log(final);

     

    Cheers

    Eric

Answers

  • Hello @Simon_King ,

    The format to do that can be made in a beastmode (see attached picture). If you make this in a 'dynamic textbox' card, you can set this as a header on your dashboard. 

    I don't know how to update the time every second.

     

    Best regards,

    Koen 

  • Hi,

     

    thanks for your answer however this date format is required in a connector API call in order to drag the data into Domo.

     

    simon 

  • Hi there,

     

    If I understood you correctly, you're building a custom connector in Domo and need the current date in the format you specified in order to make an API call. You can do that using pure JavaScript with the code below:

     

    var options = {
      weekday: 'short',
      year: 'numeric',
      month: 'short',
      day: 'numeric',
      hour: '2-digit',
      minute: '2-digit',
      second: '2-digit',
      hour12: false
    }
    today = new Date();

    var formattedDate = today.toLocaleDateString("en-AU", options) + ' GMT';

    console.log(formattedDate);

     

    I've just concatenated the " GMT" part on the end for simplicity

     

    Cheers

    Eric

     

    EDIT: documentation for the toLocaleDateString method

  • Eric,

     

    Thats great thanks. Just a minor tweak I get date

     

    Fri., 11 Oct. 2019, 09:28:00 GMT

    but need

    Fri, 11 Oct 2019 09:28:00 GMT

     

    Just a fullstop and a comma removed

     

    I will have a look but if you know how that would be great

     

    Thanks

  • eric_tetik
    eric_tetik Member
    Answer ✓

    Here's a little more formatting to get the result you need:

    var options = {
      weekday: 'short',
      year: 'numeric',
      month: 'short',
      day: 'numeric',
      hour: '2-digit',
      minute: '2-digit',
      second: '2-digit',
      hour12: false
    }
    today = new Date();

    var date = today.toLocaleDateString("en-AU", options) + ' GMT';

    // Replace period with nothing
    var date1 = date.replace(".", "");

    // Replace all instances of a comma with nothing
    var date2 = date1.replace(/,/g, "");

    // Re-add the comma after the weekday

    var final = date2.substring(0, 3) + ', ' + date2.substring(4);

     

    console.log(final);

     

    Cheers

    Eric

  • Great thanks