- Forums
- MYSQL
- PHP and MySQL Inserting Time Into Database
this tutorial will show you about how to insert or enter time or date into you database using php and mysql [2322], Last Updated: Mon Jun 24, 2024
Webune Support
Sun Jan 17, 2010
0 Comments
659 Visits
Welcome to Webune
Webune provides PHP/MySQL hosting - If you're not satisfied with your current PHP/MySQL hosting provider, Switch to Webune Today. We provide excellent servicer and support, that is why we are creating this post here to show PHP developers like you how to insert time into a MySQL Database.
for example, lets say i have a post and i want to put the time that it was created, you have two options
1. Basic - The basic way is to use the date() function in PHP, for example, lets say i want to put the time as: Jan. 17, 2010 it would use this function:
date('M'. 'd', 'Y')
so i can use this code to do the query:
PHP CODE:
<?php
$today = date('M'. 'd', 'Y');
$Sql = "INSERT INTO topics SET date = '".$today."'";
?>
NOTE: be sure that the date field type is set to variable (VAR) and not integer (INT) in your database
2. Option two is more advance but its the best and fastest to query since we are going to be using and integer for the field type so this is how the code would look like:
PHP CODE:
<?php
$today = time();
$Sql = "INSERT INTO topics SET date = $today ";
?>
try it