ASPit - Totally ASP
Search PHPit

Use this textbox to search all the content on PHPit. Seperate keywords with a space.

Advertisements
Partners
  • Online Hotel Bookings
  • Accommodation in Thailand
  • Lamai Beach Hotels Koh Samui
  • Tech Jobs
  • Yellow Pages

MySQL NOW()


Using this function you can get the current date and time in the MySQL NOW() form, in case you want to use PHP to generate it, instead of MySQL.

function mysql_now() {
$temp = getdate();

$date = $temp['year'] . "-";

if (
strlen($temp['mon']) == 1) {
$date .= "0" . $temp['mon'];
} else {
$date .= $temp['mon'];
}

$date .= "-";

if (
strlen($temp['mday']) == 1) {
$date .= "0" . $temp['mday'];
} else {
$date .= $temp['mday'];
}

$date .= " ";

if (
strlen($temp['hours']) == 1) {
$date .= "0" . $temp['hours'];
} else {
$date .= $temp['hours'];
}

$date .= ":";

if (
strlen($temp['minutes']) == 1) {
$date .= "0" . $temp['minutes'];
} else {
$date .= $temp['minutes'];
}

$date .= ":";

if (
strlen($temp['seconds']) == 1) {
$date .= "0" . $temp['seconds'];
} else {
$date .= $temp['seconds'];
}

return
$date;
}
?>
About the author
Dennis Pallett is the main contributor to PHPit. He owns several websites, including ASPit and Chill2Music. He is currently still studying.

Dennis Pallett has written 5 tutorials, 2 FAQs, and 19 codesnippets.