How do I check day for cross month

4 Leave Cover

I have an activity that only perform in a date range regardless month/year. I need to validate if the current date is >= 30 and <= 05 (next month).

Sample code below:

$t = microtime(true);
$micro = sprintf("%06d",($t - floor($t)) * 1000000);
$d = new DateTime( date('Y-m-d H:i:s.'.$micro, $t) );
$date = substr($d->format("d"),0,2);

if($date >= 30000000 && $date <= 05000000){
    $validate = true;
}

I simply cannot use >= 30 and <= 05 as it is an invalid range. Or should I need to code:

if($date = 30 || $date = 31 || $date = 01 || $date = 02 || $date = 03 || $date = 04 || $date = 05){
    $validate = true;
}
Phiter

Yeah, I think your code is ok. You could do by using timestamps I guess, but a little improvement for your code could be:

$dates = array(30, 31, 1, 2, 3, 4, 5);
if (in_array(((int)$date), $dates)
    $validate = true;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I get the day of the month in javascript?

Java: How do I get the date of x day in a month ( e.g. Third Monday in February 2012)

Given a Date Object how do I determine the last day of its month?

How do I get the last day of a month?

How do I run a script for 1st working day of every month in cron?

How do I schedule an AWS Lambda cron to run at 11:30pm on the last day of the month?

Given year & month, how to check a particular day exists in that month

How do i change Date Format in Month Day, Year in C#

How do I find the first and last day of next month?

How do I make the unique check on month of a year in Laravel

How do I select distinct rows and cross check in another table?

how can I find out the day of the month?

How do I stop SQL Server swapping the month and day?

How do I paste data from the first day of the month for the whole month?

How do I extract the Hour/Minute from a datetime object and get rid of the Year/Month/Day/Second section?

How do I Change the view from month to day view if i click on a specific day

In Meteor, how do I find a record in a collection given the year, month, day?

How do I specify from a date to the last occurence of a day in a specific month, using iCal?

How do I check the day of a datestring in python?

How do I overload the pre and post increment operators for an object that is composed of a day and month to be printed as a std::string?

How do I calculate the date in JavaScript, to get the same day in month + some month (variable)

How do i get the date from week of month and day of week with Carbon?

How do i get the first and last day value per month in pandas?

How do I get the day month and year columns?

How do defining the first and last day of the month

How do I select between 1st day of the current month and the 1st day of the following month (from current month) in postgres

How do I get the average month and day from a list of date times?

How do I make sure my column descends by year instead of the day of the month?

In JavaScript, how do I parse a Date that is always day followed by the month followed by the year?