Skip to content

Instantly share code, notes, and snippets.

@shavidzet
Last active April 29, 2016 00:01
Show Gist options
  • Save shavidzet/a4fc1d7db19afbdb72ece9bf9112f503 to your computer and use it in GitHub Desktop.
Save shavidzet/a4fc1d7db19afbdb72ece9bf9112f503 to your computer and use it in GitHub Desktop.
Set date limit for particular product

Date differences and limiter

I have developed this gist to make easy your tasks when you need to work on times function in php

You can simply make a limit where you want and what you want.

For example:
If you have shopping web-site and you want to make a date limit for specific product, Yeaaah, I have already developed this function for you!
<?php
function dateLimitReached($db_date, $secLimit) {
$format = 'Y-m-d H:i:s';
$current = date($format);
$limit = date( $format, strtotime("+$secLimit seconds", strtotime($db_date)) );
$diff = strtotime($current) - strtotime($limit);
if ($diff < 0 && $diff >= -$secLimit) return true;
return false;
}
$db_date = '2016-04-28 11:18:00'; // date from this time
$diff = dateLimitReached($db_date, 60); // function return false if expires available date
var_dump($diff);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment