skip to Main Content

I need to display Future Date in a webpage. like 24 days after today only month and day. can anyone please help me. Like

This item will deliver in :(+24 days).
e.g.
This item will deliver in: Dec 6

I like to Display Month and Day only, is it possible. Thank you.
PS. I am using WordPress and WPBakery Page Builder

2

Answers


  1. Use this function to get it:

    const displayDate = (inDays: number) => {
        const currentDate = new Date();
        currentDate.setDate(currentDate.getDate() + inDays);
        
        return currentDate.toLocaleString("en-US", { month: 'short', day: '2-digit' });
    }
    

    Just get the future date (according to inDays param) and then use the function to "extract" the date information for your needs

    Login or Signup to reply.
  2. Add this into your functions.php and output with shortocde

    [delivery_date]

    function delivery_date_shortcode() {
        // Get today date
        $today = new DateTime();
        // Add 24 days to today date
        $delivery_date = $today->modify('+24 days');
        $formatted_date = $delivery_date->format('M j');
    
        // Return the formatted date
        return "This item will deliver in: {$formatted_date}";
    }
    
    // Register the shortcode
    add_shortcode('delivery_date', 'delivery_date_shortcode');
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search