Thursday, 30 July 2015

Adding and Subtracting Dates and Times in PHP

$today = date(‘d/m/Y’);  // Todays date in date/month/4 digit year format

$yesterdaydt=date(‘d/m/Y’,strtotime(“-1 days”));  // GET Yesterdays Date


Subtracting days from a date

The following example will subtract 3 days from 1998-08-14. The result will be 1998-08-11.

$date = "1998-08-14";                                    
$newdate = strtotime ( '-3 day' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                  
echo $newdate;                                           
 
Subtracting Weeks from a date

The following example will subtract 3 weeks from 1998-08-14. The result will be 1998-07-24. Notice that the only difference in the code is the week statement.

$date = "1998-08-14";                                     
$newdate = strtotime ( '-3 week' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                   
echo $newdate;                                            
 
Subtracting Months from a date

The following example will subtract 3 months from 1998-08-14. The result will be 1998-05-14. Notice that the only difference in the code is the month statement.

$date = "1998-08-14";                                      
$newdate = strtotime ( '-3 month' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                    
echo $newdate;                                             
 
Subtracting Years from a date

The following example will subtract 3 years from 1998-08-14. The result will be 1995-08-14. Notice that the only difference in the code is the year statement.

$date = "1998-08-14";                                     
$newdate = strtotime ( '-3 year' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                   
echo $newdate;                                            
 
Adding days, months, weeks and years from a date

There isn’t really much difference from subtracting and adding dates. To add dates, just use any of the examples above and replace the negative (-) with a positive (+) e.g. ‘+3 weeks’
You could also just do:
echo date(“Y-m-j”, strtotime(“1998-08-14 -3 days”));
(sub days, weeks, months, as needed)

This adds 2 days to the current date:
 
$date = date('Y-m-j');                                   
$newdate = strtotime ( '+2 day' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                  
echo $newdate;                                           
 
This adds 2 months to the current date:
 
$date = date('Y-m-j');                                     
$newdate = strtotime ( '+2 month' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                    
echo $newdate;                                             
 
This adds 2 years to the current date:
 
$date = date('Y-m-j');                                    
$newdate = strtotime ( '+2 year' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                   
echo $newdate;                                            

This subtracts 6 hours from the current date:
 
$date = date('Y-m-j');                                    
$newdate = strtotime ( '-6 hour' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                   
echo $newdate;                                            

This subtracts 10 minutes from the current date:
 
$date = date('Y-m-j');                                       
$newdate = strtotime ( '-10 minute' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                      
echo $newdate;                                               

If you want to change if from the current date, then simple replace the current date with the desired one…

This adds 1 year to the date 2012-11-25:
 
$date = date('2011-11-25');                               
$newdate = strtotime ( '+1 year' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );                   
echo $newdate;                                            

Get the Week Start Date and ENd date 

Consider today is a saturday for the given example

$day = date('w');                                                             // Gives Day of week, returns 6 if it is saturday
$sday = $day - 1;                                                            // I need only working dates mon-sat so 6-1=5 
$eday = 6 - $day;                                                            // Excepting sunday in the list                           
$ws = date('d/m/Y', strtotime('-'.$sday.' days'));            // -5 days to current date that is monday            
$we = date('d/m/Y', strtotime('+'.$eday.' days'));          // + 0 days  to current date that is today - sat      
$lastsunday = date('d/m/Y',strtotime('-'.$day.' days'));  // Gives last week sunday date                           
$comingsunday = date('d/m/Y',strtotime('+'. 7-$day.' days')); // coming sunday                                    

like wise we can get any day of the week , note that the return result is a string

Code for Subtracting a day from given date 

$date = '09/02/2015';
$day_before = date( 'm/d/Y', strtotime( $date . ' -1 day' ) );
echo "<br/><br/>";
$db = date('d/m/Y',strtotime($day_before));

echo $db;

Wednesday, 29 July 2015

STOP loading previous pages when chrome browser started in ubuntu

While Google gets to work fixing the Chrome battery drain issue affecting Windows users, an easy interim solution may help preserve laptop battery life in the meantime.
The fix? Closing the browser when it’s not needed.

Captain Obvious

Historically, closing an application in Windows is straightforward: you click or tap on the ‘x’ window control button.
Depending on your settings, this isn’t always the case with Chrome; closing doesn’t always mean it fully exits. The browser often continues to run in the background on Windows (and Linux) – something you might never notice.

The Reason Why: You

Whether this happens or not depends on the sort of applications and extensions you have installed in Chrome. Some of these will “ask” the browser to stay awake so that they can continue to function; e.g., to deliver notifications of new e-mail messages or keep an active IRC chat alive.
Google makes it easy to tell when background apps are active: just look for the Google Chrome icon in the system tray (bottom right corner of your desktop screen). Click on this emblem to view a list of active tasks and a access a proper ‘Exit’ option.
If want to stop Chrome from running in the background entirely (i.e., so that it always exits when closed), regardless of extension, you can. You just need to tell it to.

How to Stop Chrome Running in the Background

On Windows or Linux click on the Chrome icon in the task bar/system tray, find the ‘Let Chrome run…’ option and click/tap it to disable/toggle the checkmark off.
It’s that simple. 
The behaviour can also be changed through the browser’s main settings page:
  • Click on the Chrome menu (or press Alt+E)
  • Select Settings
  • Click on the link titled ‘Show advanced settings
  • Under the section headed ‘System‘ untick the box next to “Continue running background apps when Google Chrome is closed”
To reenable the feature simply repeat the steps above but reversing the final step.