How to detect customer account years old?


Customer Account has created at 2018-05-17 15:20:35,I want to add text "Anniversary" if the account has been 1 year.

  • where do you want to add this text ? – Pawan Sep 25 '18 at 3:19
  • I want to add the text in customer account info. – Jackrose Sep 25 '18 at 3:41
  • if you can please share a snaphot of Customer Accout section , where and in which place you want to show Anniversary and Do it will be placed all the time for all the customers who completed there 1 year or 2 Year or nth year ? basically , what we have to do , make a separate custom module which can override files of customer account of that section where you want to put your content. – amit_game Sep 25 '18 at 4:47

Hey you can get do it by finding customer Created at and present data. You just need to load customer and get its Created_at value and today's date and get the difference of dates.

If you find this answer useful please mark it as solution or upvote thanks.


Use below code for it

$customerID = 2; // your customer-id
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerObj = $objectManager->create('Magento\Customer\Model\Customer')

$birthDate = date('Y-m-d', strtotime($customerObj->getCreatedAt()));

$time = strtotime($birthDate);
if(date('m-d') == date('m-d', $time)) {
    echo "Today is Birthday";
    echo "Not Birthday today";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.