Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9005981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:17:31+00:00 2026-06-16T01:17:31+00:00

Good day every one! In general, my question is about time function in php/mysql,

  • 0

Good day every one!

In general, my question is about time function in php/mysql, how i can save time in mysql database? for date I chosed “date type” in the database to save $date and i wrote this code in php:

$date=date("y-m-d");

and this is my whole code about that part:

<?php 
include_once ("connection.php");
$name=$_POST['sent_by'];
$id=$_POST['hidden_id'];
$id2=$_POST['hidden_id2'];
$message=$_POST['message'];
$submit= $_POST['submit'];
$date=date("y-m-d");
$time=time('yyyy-mm-d hh:mm:ss');


if($submit){

$place="INSERT INTO comments VALUES('','$name','$message','$id','$id2','$date','$time')";
$run = mysql_query("$place");
die("Your message have been sent Successfully !! <a href='member.php'>click here to return to your page</a>");
}



?>

for time what function i have to use? and which type i have to choose in database?

please help me!

thanks and regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:17:33+00:00Added an answer on June 16, 2026 at 1:17 am

    My advice is that you use either a timestamp or datetime type rather than the date type since you want both the date and time component. A timestamp type has some special properties you need to be aware of, but if you have the option to utilize a timestamp then that’s preferable from a storage standpoint. See this for more information.

    You also should simply let the database set the time when inserted, which can be done automatically with a timestamp or manually using NOW().

    One way of doing this, based on your code would be to change your query to be:

    $place="INSERT INTO comments VALUES('','$name','$message','$id','$id2', NOW())";
    

    Notice that you no longer want or need php to create a date variable. The value of your DATETIME or TIMESTAMP column will be set to the system time of the mysql database server.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

good day every one. what are the effect of re-cache if i use it
Good day every one! If someone could help me on my problem I'm encountering.
Good day. The one thing I now hate about Haskell is quantity of packages
Good day everyone! I have a problem regarding my date. It needs to be
I've read that It's a good experience to use a fresh image every day
The following User History table contains one record for every day a given user
Good day. I have an app that has one main activity which holds 3
Good Day, I'm currently designing database structure for a website of mine. I need
Good day, This is more web service design than programming question I think. I'll
Just a general question. Is it better for database keep values or NULLs? I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.