DEV Community

andysaktia
andysaktia

Posted on • Edited on

Update Default Date Display

This time I will process the data that appears on the page with special conditions, where when today is Saturday or Sunday, the date will display the previous date, namely Friday.

Stages:

  1. Today's date, time form and day number (w)
  2. Giving the day deduction parameter ($minus)
  3. Update the date to be displayed ($t)
    $today= date('Y-m-d'); // bisa diganti dengan GETtanggal 
    $time = strtotime($today);
    $day_num = date('w', $time);

    if ($day_num == '0') {
      $minus = '-2 day';
    } elseif ($day_num == '6') {
      $minus = '-1 day';
    } else {
      $minus = '0 day';
    }

    $t = strtotime($today . $minus);
    $t = date('Y-m-d', $t);
Enter fullscreen mode Exit fullscreen mode

or

  // case date adalah hari ini
    $day_num = date('w'); 

    if ($day_num == '0') {
      $minus = '-2 day';
    } elseif ($day_num == '6') {
      $minus = '-1 day';
    } else {
      $minus = '0 day';
    }

    $t = date('Y-m-d', strtotime($minus));
Enter fullscreen mode Exit fullscreen mode

DONE

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay