How to subtract Date now to date saved in database in php

Leave a Comment
Step 1: Create Database .. name the database as subtract_me then click the button create..

Step 2: Click the SQL at the top…and paste the code..


CREATE TABLE IF NOT EXISTS `subtract_date` (
  `id` int(255) NOT NULL AUTO_INCREMENT,
  `date` date DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `subtract_date`
--

INSERT INTO `subtract_date` (`id`, `date`) VALUES
(1, '2017-02-01'),
(2, '2017-02-27');

Step 3: Your database create …and then open sublime or notepad++ for coding in php .. and paste the code below ….save the code as conn.php
<?php
$conn=mysql_connect('localhost','root','');
mysql_select_db('subtract_me');
if($conn)
{
                 
}
else
{
                die();
}
 ?>



Step 4: After you create the conn.php you can now click the ctrl n for new and paste this code...

<?php
include 'conn.php';

                    echo '<h2>This Result subtract the date now to date save in database</h2>';
                  $sql=mysql_query('SELECT DATEDIFF( NOW() , DATE ) AS subtract FROM subtract_date')or die(mysql_error());
                  while($result=mysql_fetch_array($sql)){
                
                    $subtraction_result = ''. ($result['subtract']). '';

                       echo '<b>'.$subtraction_result.'</b>';
                       echo '<br>';
            
                  }
?>



The output of the program is this::
Download this Code: CLICK ME

please comment and share :)
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment