PHP and MySQL Inserting Time Into Database

RegisterLogin
PHP and MySQL Inserting Time Into Database
Post Description: this tutorial will show you about how to insert or enter time or date into you database using php and mysql
Tags: Php, And, Mysql, Inserting, Time, Into, Database
This Post Was Posted On Jan 17, 2010 By Webune Support #3059
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
17p-0-interger-field.gif

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
©2012 Webune Forums - Wed Dec 12, 2012 11:54 pm
Powered by: Webune Forums V3