-5

I am developing a web application for the gym. if he paid the fee for the existing month the area of that month is green. and after every 30 days completion, the next month area will be red if he is not paid the fee. so the problem is that, that how can I find that the student completes the 30 days.

  • 1
    Could you please add some code? – Michael Dec 22 '16 at 09:32
  • 1
    what you tried so far? – Chonchol Mahmud Dec 22 '16 at 09:35
  • 1
    Welcome to SO. Please read [What topics can I ask about](http://stackoverflow.com/help/on-topic) and [How to ask a good question](http://stackoverflow.com/help/how-to-ask) And [the perfect question](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) And how to create a [Minimal, Complete and Verifiable example](http://stackoverflow.com/help/mcve) SO is **not a free Coding or Code Conversion or Debugging or Tutorial or Library Finding service** ___Here at SO we fix your attempts, we do not code things for you___ – RiggsFolly Dec 22 '16 at 09:35
  • no sir i have no code i just thinking that how can i do this.. – Imad ud din Dec 22 '16 at 09:36
  • i just need an idea for this dont give code – Imad ud din Dec 22 '16 at 09:38

2 Answers2

0

Its not very clear what you want to do, but I think this is what you want to do. Its pretty simple to get the distance between two dates in days.

Finding the number of days between two dates

Store the count of days in a variable or array and just use an if-statement.

Community
  • 1
  • 1
Pingbeat
  • 305
  • 1
  • 9
0

Explainations

You can use the DateTime Class in order to manage your dates.

What you could do is create two object : one for the date for today, and one for the subscription date (that you will get from a database, a file, an API, ...). You can use the constructor from the DateTime class to do so.

Next, you'll have to find the difference in days between those two dates. So you'll use the DateTime::diff() method in order to do the difference between the subscription date and today's date.

And finally, you'll have to format the difference in a more human readable format, so in days for you. You can then proceed on displaying, calculating and formating your CSS/HTML accordingly.

Source-code

<?php

$subscription   = new DateTime('2016-10-12'); /* change the date accordingly */
$now            = new DateTime('now'); /* you can add precision on hours and minutes as well */

$interval = $subscription->diff($now); /* interval between the subscription and today */
$daysInterval = $interval->format('%r%a'); /* %r : +/-, %a : days of interval */

if ($daysInterval > 30) {
    echo 'Due date is past (' . ($daysInterval - 30) . ' days late)';
    /* process here all the CSS/HTML you need */
} else {
    echo 'You still have some time before due date';
    /* process here all the CSS/HTML you need */
}

Online demo

Online demo.

Documentation

PHP : DateTime.

PHP : DateTime::diff.

PHP : DateInterval::format.

Amin NAIRI
  • 2,292
  • 21
  • 20