0

How can I store the actual hour and minute,from a mysql table, in variables?I want to store hour and minute like this:

//Connect database
$con = mysql_connect("localhost","root","ufmg3duc");
  if (!$con)
    die('Could not connect: ' . mysql_error());

  //Select database
  mysql_select_db("stream_net", $con);

  //Read data
  $query_month = $_GET['form_month_tend'];
  $query_day = $_GET['form_day_tend'];
  $query_year = $_GET['form_year_tend'];
  if ($query_mes == NULL)
    $query_mes = date("m");
  if ($query_dia == NULL)
    $query_dia = date("d");
  if ($query_ano == NULL)
    $query_ano = date("Y");

How can i do like i did before but with Hour and MInutes?

1
  • Please, stop using mysql_* functions already. The entire extension is deprecated (and not a moment too soon). It's alternatives are far more powerful, reliable and up-to-date. These new extensions are PDO and mysqli_* (the i in mysqli_* stands for improved). Commented Nov 21, 2013 at 10:44

1 Answer 1

2

storing Time and Dates into an SQL database using php

You should use the datetime datatype for your requirement. It will store both the date and time from your input field based on your query.

For retrieving the datetime you can use the mysql's date_format() function or PHP's date() function. The datetime will always be stored according to the server's time and not on the clients time.

For Hour & Minute

print date('H:i');

$hour = date('H');

$min = date('i');

Sign up to request clarification or add additional context in comments.

1 Comment

+1 for the important hint: "The datetime will always be stored according to the server's time and not on the clients time."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.