logo
down
shadow

how to get days of difference between two dates in php


how to get days of difference between two dates in php

Content Index :

how to get days of difference between two dates in php
Tag : php , By : user185751
Date : November 29 2020, 12:01 PM

this one helps. Firstly, you'll need to make your $expire_date into a Carbon instance:
$expire_date = Carbon::parse("2019-07-22");
$interval = $expire_date->diffIndays(now());

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

find days difference between 2 dates and how many days in each month


Tag : java , By : hyperNURb
Date : March 29 2020, 07:55 AM
This might help you I think there is a relatively simple solution to this, the algorithm is as follows:
import java.util.Calendar;

public class test {

    public static void main(String[] args){

        Calendar today = Calendar.getInstance();
        Calendar problemDate = Calendar.getInstance();

        today.set(2013, 01, 05);
        problemDate.set(2012, 11, 05);
        System.out.println(today.getTime());
        System.out.println(problemDate.getTime());

        // This might need further validation to make sure today >= problemDate
        int diffYear = today.get(Calendar.YEAR) - problemDate.get(Calendar.YEAR);
        int differenceInMonths = diffYear * 12 + today.get(Calendar.MONTH) - problemDate.get(Calendar.MONTH);
        //int differenceInMonths = today.get(Calendar.MONTH) - problemDate.get(Calendar.MONTH);

        for(int i = 0; i <= differenceInMonths; i++) {
          int daysDifference;

          if (differenceInMonths == 0) {
             daysDifference = today.get(Calendar.DAY_OF_MONTH) - problemDate.get(Calendar.DAY_OF_MONTH);
          } else {
            if ( i == 0) { // first month
              daysDifference = problemDate.getActualMaximum(Calendar.DAY_OF_MONTH) - problemDate.get(Calendar.DAY_OF_MONTH);
            }
            else if( i == differenceInMonths ) { // last month
              daysDifference = today.get(Calendar.DAY_OF_MONTH);
            }
            else {
              Calendar cal= Calendar.getInstance();
              cal.set(Calendar.MONTH, problemDate.get(Calendar.MONTH) + i);
              daysDifference = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
            } 
                  }

          System.out.println(daysDifference);
        }
    }
}
Tue Feb 05 14:35:43 GMT 2013
Wed Dec 05 14:35:43 GMT 2012
26
31
5

Elapsed days between two dates always giving one days difference


Tag : ios , By : Sinisa Ruzin
Date : March 29 2020, 07:55 AM
I hope this helps . The date format doesn't have anything to do with it. What is happening is the NSDateComponents are giving you what you are asking for, the total difference in years, months, and days. If you want just the days, you need to only provide NSDayCalendarUnit. The docs make this clear:

Excel VBA to find out difference between two dates in days. where dates come from different sheets


Tag : excel , By : Lee KW
Date : March 29 2020, 07:55 AM
like below fixes the issue I want to get date difference in days from two dates using a macro in Excel. Addition on that first date should be from sheet1 , Here is the solution:-
Private Sub CommandButton1_Click()
Dim currDate As Date
Dim dateOffset As Integer
Dim count1 As Integer
Dim str As String
Dim cuntfinal As Integer
Dim strfinal As String
countfinal = 2
 count1 = 2
 count0 = 2
 strdate = "d" & CStr(count0)
For Each cell In Range(Sheet3.Range(strdate), Sheet3.Range(strdate).End(xlDown))
 strdate = "d" & CStr(count0)
 count0 = count0 + 1
 If cell Is Nothing Then GoTo line10
  startDate = Sheets("Sheet3").Range(strdate)
  str = "h" & CStr(count1)
 For Each cell1 In Range(Sheet3.Range(str), Sheet3.Range(str).End(xlDown))
  count1 = count1 + 1
  GoTo line20
  Next cell1
line20:
 If cell1 Is Nothing Then GoTo line10
currDate = Sheets("Sheet3").Range(str)
If currDate = "12:00:00 AM" Then GoTo line40

dateOffset = DateDiff("d", startDate, currDate)
line30:
strfinal = "j" & CStr(countfinal)
Sheets("Sheet3").Range(strfinal) = dateOffset
countfinal = countfinal + 1
line10:
Next cell
line40:
strfinal = "j" & CStr(countfinal)
Sheets("Sheet3").Range(strfinal) = " "
countfinal = countfinal + 1
 GoTo line10
  End Sub

How to get the difference between two dates with 360 days/year, 30 days/month format?


Tag : php , By : pttr
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I can get the difference between two dates (DD/MM/YY format) with the following code; , Here is the way to do it:
function diff360($date1, $date2) {
    $date1 = new DateTime($date1);
    $date2 = new DateTime($date2);
    $diff = $date1->diff($date2);
    $days = ($date2->format('d') + 30 - $date1->format('d')) % 30;
    return array(
        "y" => $diff->y,
        "m" => $diff->m,
        "d" => $days,
        "totaldays" => $diff->y * 360 + $diff->m * 30 + $days
    );
}

$result = diff360("2016-02-06", "2016-03-06");
var_export($result);
array (
  'y' => 0,
  'm' => 1,
  'd' => 0,
  'totaldays' => 30,
)

Add number of days to datetime and then find difference in days between two dates


Tag : php , By : Richard
Date : March 29 2020, 07:55 AM
seems to work fine I have saved a date in mysql table in date('Y-m-d H:i:s') format , You can do it easily using DateTime class, look here:
$blacklisted_date = "2018-07-22 17:57:24";
$blacklisted_days = 7;

$date1 = new DateTime($blacklisted_date); // blacklisted
$date1->add(new DateInterval("P{$blacklisted_days}D")); // add N days

$date2 = new DateTime(); // now
$interval = $date1->diff($date2); // get diff
echo $interval->days; // in days
Related Posts Related QUESTIONS :
  • Using json to import multidimensional data
  • passing data from the view to the controller, where the data comes from another controller
  • How to extract integer and decimal numbers in PHP string correctly?
  • Parsing Sub-Object from an XML Feed with objects
  • Getting error "Unknown column 'text' in 'field list'"
  • How to properly get onedrive access token via php and curl
  • How to add spell check to a php function
  • Is it posible to create css rules with php?
  • Pretty URL with $_GET method
  • Wordpress always load same page - index.php
  • Find value in array and return with new from different array
  • PHP multiple file upload with different keys
  • Can't modify times one a time without weird errors
  • Get size of scraped image with domcrawler (Goutte)
  • Laravel - Ordering a collection of models
  • PHP Fatal error: Uncaught Error: Call to a member function setFetchMode() on boolean
  • Strict Standards: Only variables should be passed by reference in /main_dir/sub_dir/backup.php
  • Uncaught Google_Exception: (update) unknown parameter: 'copyRequiresWriterPermission'
  • Laravel 5 form does not redirect with old input
  • How to get values greater than or equal to in Mysql database sql when its a value like 1:00 PM?
  • PHP datediff overday issue
  • Masking an auto incrementing primary key
  • How to grab a String BEFORE a certain word
  • ZF2 Routing Multiple Controllers based on route constraints
  • How to deregister/dequeue jquery.sticky.js in Elementor (Pro)?
  • How to fix errors counting words in text plain with PHP?
  • How to get View data in Laravel in custom helper or directive
  • Creating a new data entry into a database with eloquent and trying to access the variable in the url
  • How to test authentication using Laravel Dusk?
  • PHP parse_str not getting all $_GET variables
  • Variable issues in php class
  • Get orders between dates in Codeigniter
  • Eloquent Special Chars Issue
  • Keeping leading zeros column Mysql
  • Current level navigation in Wordpress
  • Add a custom text to WooCommerce cart items if the product has a specific shipping class
  • Error connecting to CommissionJunction Token : [60] SSL certificate problem: unable to get local issuer certificate
  • How do I add a new key value pair to an object in PHP?
  • Http post request to php with dart
  • How to add a route in with blade into parameters of a component
  • How can i get the source of a 777 - CHMOD php file?
  • Convert 2010-04-16 16:30:00 to "Tomorrow Afternoon"
  • How can I hide a $_GET variable to be more secured in PHP?
  • Login to Gmail Inbox using Curl?
  • Upload Excel or CSV file to MySQL with PHP
  • Outlook Marking Email as Junk Email
  • Upload an image using class.upload.php via AJAX, display image in form using jQuery
  • mysql_connect() causes page to not display (WAMP)
  • How to limit a users uploaded image size using PHP
  • What's the difference whether or not to run PHP in safe mode?
  • Logging in to a website cURL
  • Using php to create a password system with chinese characters
  • PHP is not called properly in IE using set interval function in Javascript
  • How to read pdf, ppt, xl, doc files content into a string in php/python
  • php script for currency conversion
  • In PHP... best way to turn string representation of a folder structure into nested array
  • PayPal for Indian Rupees (INR) any solution
  • PHP Deployment to Live Server
  • Ideal Multi-Developer Lamp Stack?
  • How can I save an image from a file input field using PHP & MySQL?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com