Geoff Cox wrote:
Hello,
at the moment I can add the combined date and time into MySQL using
php
$dt1 = date("Y-m-d H:i:s");
is it possible to add the date and time separately?
I thought it might be
$dt1 = date("Y-m-d");
and
$dt2 = time("H:i:s");
but this doesn't seem to work ...
Cheers
Geoff
I would agree that while your question IS a PHP question, the solution
may be a MySQL solution. Next time you may consider a cross-post (both
newsgroups in the TO: field :) )
You state "doesn't seem to work"... What is the error and/or result and
what is the result you are expecting. What is the data-type of the
column you are attempting to store this information? CHAR? VARCHAR?
DATE? TIMESTAMP? Just remember, while you can store a date in a
CHAR/VARCHAR column, doing date arithmetic on it will still require
converting it to date/time.
What is the end goal and why? The "why" (short explanation will do)
would determine which one of a thousand methods you could or should be
using to make things easy for you, your app and your db. If your
database has a DATETIME and TIMESTAMP column you could use the MySQL
function NOW() or the PHP time() both of which derive the "unix
timestamp" which is number of seconds from EPOCH time for that platform.
Epoch time for most UNIX OS's is 01/01/1970, for Windows it is
01/01/1980 00:00 (and for OpenVMS (formerly DEC VMS) it is 17-Nov-1858
00:00.
See
http://dev.mysql.com/doc/refman/5.0/en/datetime.html for further
explanations of date/time data-types.
Any formating or retrieving time ranges can be derived from this
DATETIME or TIMESTAMP field. I tend to let the database do the database
time and the parse that date/time. **Generally** speaking, time without
a date is pretty useless YMMV. Dates without time *can* be useful for
things like past/future shipping dates etc or any one of many, many more
examples that could be conceived.
IMO saying that something did or will occur at 2PM is pretty useless
without knowing which date. And if this information is required for
reporting that "most queries are performed between 2 and 3AM", it can be
easily derived from the full timestamp which would also require one less
column to maintain.