Re: date
| From: | Simon Garner | Date: | Mon, 05 Mar 2001 01:57:43 +0000 |
| Subject: | Re: date | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-42550@lists.php.net to get a copy of this message | ||
From: "Michael Hall" <lists@mulga.com.au>
>
> Yes you can. Include a field in your db called 'date' or whatever.
>
> Generate the date in your script using:
>
> $today = date("Y-m-d");
>
> Then simply add the date to the db along with everything else.
> There are lots of ways to format dates, too many to describe here.
> Have a look at the PHP manual.
> Also, if you make the data-type of the date field 'date', your options for
> formatting are more limited. That stuff is all in the MySQL manual.
>
> Michael
>
>
> On Sun, 4 Mar 2001, george wrote:
>
> > Can you mark the date when an entry is placed in the db and then get
that
> > date to display when the info is pulled out
> >
> > TIA
> >
> > george
> >
If you make the field in the database of type "DATETIME" then you can insert
dates and select formatted date values using MySQL's date and time
functions. (I assume you're using a MySQL database.) There is no need to use
PHP's date functions.
Examples:
CREATE TABLE mytable (
...
mydate DATETIME,
...
)
To insert the current date, use NOW() as the date value:
INSERT INTO mytable VALUES (..., NOW(), ...)
To select the date formatted as "Saturday March 5th 2001 12:30 PM":
SELECT
col1,
col2,
DATE_FORMAT(mydate, '%W %M %D %Y %r') AS mydate,
col4
FROM mytable
http://www.mysql.com/doc/D/a/Date_and_time_functions.html
Cheers
Simon Garner