Monday , February 3 2025

Display the date + a few days from the current one

The task in short: you need to make the delivery date + 5 days from the current date in PHP, with the output of the month in the genitive case in RU. But you can ignore custom edits for that language version.

The method with date( ‘d FY’ ); is not used, because the result will be like this: 11 February 2022, but you need February 11, 2022 + 5 days = February 16, 2022.

In this article, I have added a copy-paste code, the result of this echo will be February 16, 2022:

$searchbl = array ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$replacebl = array ('января', 'февраля', 'марта', 'апреля', 'мая' , 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря');

echo str_replace($searchbl,$replacebl, date('d F Y', strtotime("+5 days"))); echo ' г.';

I made this solution when I needed to make a delivery snippet on ModX and call it in a template.

Update: I had to add another condition, and do + 5 days for delivery for all days of the week except Tuesday, and for Tuesday: delivery + 6 days, because Sunday is a day off. Here is the complete code with this edit:

$searchbl = array ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$replacebl = array ('января', 'февраля', 'марта', 'апреля', 'мая' , 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря');

if(date('D') == 'Tue') { 
  echo str_replace($searchbl,$replacebl, date('d F Y', strtotime("+6 days")));
}
else echo str_replace($searchbl,$replacebl, date('d F Y', strtotime("+5 days"))); echo ' г.';

About iryna

I'm Iryna, a web developer from Ukraine with a decade of experience solving complex technical challenges in the world of freelance. Throughout my career, I've worked on everything from troubleshooting server-side issues and optimizing website performance to enhancing user interfaces. On this blog, I share detailed solutions to the technical problems I’ve encountered and methods that have worked best for me. In addition to my technical expertise, I’m also passionate about digital drawing. I hope the tutorials and insights I provide here will help both fellow developers and creatives alike in their own projects.

Check Also

Css styles for WordPress admin in functions.php

If you need to add individual styles, and they are only a couple of lines, …

Leave a Reply

Your email address will not be published. Required fields are marked *