user1629990
user1629990

Reputation: 33

How do I get next date by day of week and time

I want to get next class date by day of week and time. For example all classes are held on Tuesday and Saturday at 10:45pm So I want to display date of next class to be held from current day/time.

Without time I am able to get. But what if today is Tuesday 4pm and class is Tuesday 10:45pm then it should show me today's date, and not Saturday as next class after today is Saturday.

I tried a test code with time but it is not working.

$nextTuesday = strtotime('next tuesday 10:59PM');
echo date('Y-m-d', $nextTuesday);

If I am giving time it is not working.

With time it should show current date if day is same and time has not passed.

Upvotes: 1

Views: 44

Answers (1)

user1629990
user1629990

Reputation: 33

Okay I used my logic and solved it.

    date_default_timezone_set("ET");
    $currentday=date('Y-m-d H:i:s');
    $currentdayW=date("l", strtotime($currentday));



    if (($currentdayW=="Tuesday") ||($currentdayW=="Friday"))
    {
    $chktime = date('Y-m-d 21:00:00');
    if ($chktime > $currentday) { $drawdate =  $chktime;}

    }

    if ((($currentdayW=="Tuesday") && ($chktime < $currentday)) || 
     ($currentdayW=="Wednesday") || ($currentdayW=="Thursday"))
    {
    $drawdate = strtotime('next friday');
    $drawdate=date('Y-m-d 21:00:00', $drawdate);
    }
    if ((($currentdayW=="Friday") && ($chktime < $currentday)) || 
    ($currentdayW=="Saturday") || ($currentdayW=="Sunday") || 
    ($currentdayW=="Monday"))
    {
     $drawdate = strtotime('next tuesday');
     $drawdate=date('Y-m-d 21:00:00', $drawdate);

     }

     echo $drawdate;

Upvotes: 0

Related Questions