Announcement

Collapse
No announcement yet.

Strange behavior of sc_date_dif macro

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Strange behavior of sc_date_dif macro

    Hi,

    I have a strange problem with the sc_date_dif macro.

    I try to find out by date if a licence is valid or not. So I have a field in a grid "valid until" and a test field "days".
    The field "valid until" is a date field without regional settings and a detail mask "d-m-Y".

    In the grid's events onRecord I put this code:

    Code:
    $today = date("Y-m-d");
    $validuntil = {licence_valid_until};
    
    
    {days} = sc_date_dif($today, 'dd.mm.aaaa', $validuntil, 'dd.mm.aaaa');
    
    if({days} > 0)
    {
    
    	{status} = 'ungültig';
    	//if amount is bigger then 0, means that current date is bigger then {field_due_date}
    	//send an email to the user, this bill is overdue.
    }
    elseif({days} == 0)
    {
    
    	{status} = 'heute fällig';
    	//if amount is 0, means that current date igual {field_due_date}
    	//send an email to the user, today is the payment day
    }
    elseif({days} < 0)
    {
    
    	{status} = 'gültig';
    	//if amount is less then 0, means that {field_due_date} is bigger then the current date
    	//dont do nothing, the due date didnt pass yet
    }
    As result in my test field "days" I get strange results like negative numbers (-1431 for 23.09.2014 or for 24.04.2015, 27.04.2015 and 30.04.2015 I get for all '365')

    I experimented with all combinations of dd.mm.aaaa and Y-m-d .... but can't get the correct result.

    Can anyone help?

    Joe

  • #2
    Ditch the sc_date_dif() macro and do it in plain php (PHP 5.3 required).

    Code:
    $today = new DateTime();
    $validuntil = date_create({license_valid_until});
    {days} = date_diff($validuntil,$today)->format('%R%a');

    jsb

    Comment


    • #3
      Thanks jsb,

      works perfect

      Joe

      Comment

      Working...
      X