Date in Unix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BigBoss
    Member
    • Nov 2023
    • 86

    Date in Unix

    Hello, in an API request I receive the date in Unix format. How can I convert, for example, '1719240582' to give us the date: 24/06/2024?"

    If possible, can I use a formula or a script, or something easy?"
  • Firyo
    Senior Member
    • Jun 2022
    • 134

    #2
    Hi there,

    I don't believe such a thing exist in the formula functions.
    In PHP, you can use something like this

    PHP Code:
    <?php
    $dateTime = new DateTime();
    $dateTime->setTimestamp('1719240582');

    Comment

    • lazovic
      Super Moderator
      • Jan 2022
      • 810

      #3
      Hi BigBoss,

      You can try using the following formula script, but keep in mind that with this option, there is no precision down to the second:
      Code:
      $unixTimestamp = 1712241582;
      
      $days = number\floor($unixTimestamp / 86400);
      $remainingSeconds = $unixTimestamp % 86400;
      $hours = number\floor($remainingSeconds / 3600);
      $remainingSeconds = $remainingSeconds % 3600;
      $minutes = number\floor($remainingSeconds / 60);
      
      $baseDate = '1970-01-01 00:00:00';
      
      $convertedDate = datetime\addDays($baseDate, $days);
      $convertedDate = datetime\addHours($convertedDate, $hours);
      $convertedDate = datetime\addMinutes($convertedDate, $minutes);

      Comment

      • BigBoss
        Member
        • Nov 2023
        • 86

        #4
        I will try both possibilities thank you

        Comment

        Working...