-2

I want to do a countdown to my ICO_EndDate field from current date..

I am very beginner, I have read on the other pages about it.

Here is the code I use in my template file, the field EndDate is already being called on that page and work properly to display the ending date:

ICO Start in ".TIMESTAMPDIFF (Days,"CURRENT_DATE","[$tbl_prfx.'enddate'"]) day(s)</div>
Dejv
  • 944
  • 2
  • 14
  • 31
JSQC
  • 13
  • 6

1 Answers1

0

First, extract the number of days left from the database using simple query like this:

Using Mysqli extension:

$con = new mysqli("localhost","my_user","my_password","my_db");
$con->set_charset("utf8mb4");
$result = $con->query('SELECT datediff(' . $tbl_prfx . 'enddate, CURRENT_DATE)');
$row = $result->fetch_row();
$days = $row[0];

Using PDO extension:

$con = new PDO("mysql:host=localhost;dbname=my_db;charset=utf8mb4","my_user","my_password");
$result = $con->query('SELECT datediff(' . $tbl_prfx . 'enddate, CURRENT_DATE)');
$row = $result->fetch();
$days = $row[0];

Then just print the value of the variable to your HTML:

... ICO Start in " . $days . " day(s)</div>"
Dejv
  • 944
  • 2
  • 14
  • 31
  • Because he tagged the question with `mysql` tag, which led me to believe he uses mysqli in combination with php, since `mysql` extension is deprecated or even removed. – Dejv Jun 10 '19 at 20:59
  • Thank you for suggestions. I improved the answer. @JSQC, I hope it gives you at least some idea. Please feel free to contact me for further discussion. – Dejv Jun 10 '19 at 21:16
  • Now to semantics of your answer. What would be the value of `$tbl_prfx`? I am thinking something along the lines of `$tbl_prfx = 'enddate, CURRENT_DATE()) FROM myTable WHERE 0 < DATEDIFF('` http://www.sqlfiddle.com/#!9/4f7265/1/0 – Dharman Jun 10 '19 at 21:39
  • @Dharman the $tbl_prfx is ICO.. its called a little higher in the code.. I want to do the count down from today until ico_enddate – JSQC Jun 11 '19 at 03:18
  • 1
    @Dejv I will try that in the morning and let you know, thank you – JSQC Jun 11 '19 at 03:20