Monday, 27 May 2013

Get date plus or minus today

Greetings from Urdhva Tech!!

Several times I have came across same requirement of getting few days back from today, or few days after today. SugarCRM comes with few very handy date utility functions, and there is one which does the job!

global $timedate;
$today = $timedate->getInstance()->nowDbDate(); // Today
$earlier = $timedate->asDbDate($timedate->getNow()->modify("-30 days")); // 30 days before!
$later = $timedate->asDbDate($timedate->getNow()->modify("+2 months")); // 2 months later!

echo "Today:".$today;
echo "<br />30 days before:".$earlier;
echo "<br />2 months later:".$later;

Simple! Isn't it?

Take a look at include/TimeDate.php for many other suitable date time functions.

Comments are welcome!

Follow us on Twitter @urdhvatech

Glimpse of our plug-ins & products.

1 comment:

  1. Follwing code returns only the date part pf current date
    $today = $timedate->getInstance()->nowDbDate(); // Today - Output e.g. "2015-10-12"

    If we want both date and time then simply call the nowDb as shown below:
    $today = $timedate->getInstance()->nowDb(); // Current Date and Time - Output e.g. "2015-10-12 08:19:35"


Urdhva Tech Pvt. Ltd. Powered by Blogger.

Urdhva Tech

My photo
SugarCRM Consultants Contact us at Skype : urdhvatech

Search This Blog

Stay connected Socially


Total Pageviews

Popular Posts