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.

No comments:

Post a Comment

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