Search
 
SCRIPT & CODE EXAMPLE
 

PHP

12 months service expiary in php

<?php

// Careful! strtotime() will interpret 12/10/2020 as "10 December 2020", where you expect it to be 12 October 2020!
// Consider the code below for an alternative, more robust solution.

$today = new DateTime;

// Added time for uniformity.
// "Notice of default" used to indicate the final date for possible payment,
// before services are suspended and/or legal action is taken.
// use setDate() and setTime() to explicitly set the date/time, to avoid caveats with international date formats
// as pointed out above.
$noticeOfDefaultAt = (new DateTime)->setDate(2021, 2, 10)->setTime(7, 0);

// First reminder (yellow) sent 3 months before expiration date.
// DateInterval() accepts a formatted string which decodes here to:
// P = Period of
// 3 = 3
// M = Months
// Use sub() to get the period offset from the final payment date ($noticeOfDefault)
$firstReminderAt = (clone $noticeOfDefaultAt)->sub(new DateInterval('P3M'));
// Second reminder (orange) sent 1 month before expiration date.
$secondReminderAt = (clone $noticeOfDefaultAt)->sub(new DateInterval('P1M'));

// Default to transparent if within payment period.
$bgColor = 'transparent';

if ($today >= $firstReminderAt && $today < $secondReminderAt)
    // Today is within grace period of first reminder.
    $bgColor = 'yellow';

if ($today >= $secondReminderAt && $today < $noticeOfDefaultAt)
    // Today is within grace period of second reminder.
    $bgColor = 'orange';
    
if ($today >= $noticeOfDefaultAt)
    // We have a really sh*tty customer. Send legal team.
    $bgColor = 'red';

// Change the color names to any rgb-hex value you want and use them in your "style" attribute.
echo $bgColor;
Comment

PREVIOUS NEXT
Code Example
Php :: multiple submit button form to multiple php files 
Php :: laravel slug for non-english words too 
Php :: cf7 first_as_label 
Php :: numeros positivos input laravel 
Php :: multiple slug in route 
Php :: Laravel eloquent tricks 
Php :: laravel check if pagination is empty 
Php :: undefined variable require_once 
Php :: wp register_setting access saved value 
Php :: HASHING in php double scripting 
Php :: rendomly mix array position in php 
Php :: tina4 add debugging 
Php :: php select disable submit no value 
Php :: ubuntu where are laravel logs stored 
Php :: keep track of view count php 
Php :: datetime confict function php 
Php :: set owner symfony 
Php :: wordpress register_post_type capability gutenberg 
Php :: conect_from_db_datalayer 
Php :: php base64 encode utf8 
Php :: multi domain codeigniter 
Php :: Between Two Dates day count and removed Sunday using php 
Php :: Ciclo for PHP ejemplos 
Php :: Laravel Mix npm run production error 
Php :: create new laravel project 
Php :: session 
Php :: php boolean 
Php :: my xampp 
Php :: serialise php 
Php :: php artisan migrate error 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =