Jump to content

Date function


wrathican

Recommended Posts

hey, ive never used the date function before and now i need to know how to get it and format it to insert into a mysql databse and also get it from a mysql database and format it for being echoed.

i know how to pull stuff from DB's and insert them no problems but im just stuck with this.

any help?

Link to comment
Share on other sites

Store the date as a timestamp and then format it any way you want when you want to display it.

 

<?php

//Current timestamp - Ready to be inserted into your db.
$mydate = time(); 
//Takes timestamp and formats it to display as: June 26, 2007
$showdate = date("M d, Y", $mydate);

?>

Link to comment
Share on other sites

here is an example snippets from my site that may help you..

 

this stores the date/time in database

    $sql2 = "UPDATE employees SET last_login=NOW() WHERE username = '$checkuser' LIMIT 1";   

 

 

this will select date time from table for display on web page in standard time

 

$last_login = ("SELECT DATE_FORMAT(last_login,  '%b %e %Y at %r') aS last_login FROM employees WHERE username = '$checkuser' LIMIT 1");

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.