Highlight n value in date ()

I want to implement a Javascript countdown timer that has a month value subtracted by 1.

To dynamically get a date using PHP, I use this code:

$date = "2014:3:19 00:00:00";
$newDate = date("Y, n, j, H, i", strtotime($date));

What returns:

2014, 3, 9, 00

My question is how can I subtract the value nby 1, so the final output will always be like this:

2014, (3-1), 9, 00
+4
source share
3 answers

If you mean minus one month, you can do the following:

$date = "2014-3-19 00:00:00";
$newDate = date("Y, n, j, H, i", strtotime('-1 month', strtotime($date)));

And it 2014, 1, 19, 00will be 2013, 12, 19, 00, but not 2014, 0, 19, 00.


Update:

You want to pass the date to the jQuery plugin ( jquery.magicbusmultimedia.net ).

The plugin asks you to pass a javascript date object.

So you can do:

$('#myCounter').mbComingsoon(new Date(<?php echo strtotime($date); ?> * 1000));
+1
source

DateTime() ( , ):

$date = "2014-3-19 00:00:00";
$date = (new DateTime($date))->modify('-1 month')->format("Y, n, j, H, i");

$date = "2014-3-19 00:00:00";
$date = (new DateTime($date))->diff(new DateInterval('P1M'))->format("Y, n, j, H, i");
+3

$ date = "2014-3-19 00:00:00"; $ newDate = date ("Y, n, j, H, i", strtotime ('- 1 month', strtotime ($ date))); And 2014, 1, 19, 00 - 2013, 12, 19, 00, but not 2014, 0, 19, 00.

0
source

Source: https://habr.com/ru/post/1532752/


All Articles