Forum Moderators: coopster

Message Too Old, No Replies

getting the date/time in PHP

this should be simple

         

mylungsarempty

7:52 am on Oct 10, 2003 (gmt 0)

10+ Year Member



What code should i use to retrieve the exact date and time a person signs up with my site, and how exactly should i store it in mysql?

ukgimp

8:01 am on Oct 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could just use a datestamp system

insert into table (field1,datefield) values ('$field1',NOW())";

dreamcatcher

4:15 pm on Oct 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Alternatively you can use PHP`s date() function.

$date = date("D j M Y, G:ia");

<input type="hidden" name="adddate" value="<? echo $date;?>">
<input type="text" name="name">

Create a VARCHAR field in your database to store the value of $adddate.

INSERT INTO table (namefield, datefield) VALUES ($name, $adddate)

:)

mylungsarempty

5:15 am on Oct 16, 2003 (gmt 0)

10+ Year Member



$date = date("D j M Y, G:ia");

How would i modify this to make the date in my database read more like 02/31/2004?

dmorison

5:47 am on Oct 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How would i modify this to make the date in my database read more like 02/31/2004?

See the PHP reference for the date() function, here:

[uk.php.net...]

You just need to change the letters in the format string to make the date appear just how you want it...

jatar_k

5:50 am on Oct 16, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



how about

$date = date [ca.php.net]("m/d/Y");

<added>dmorison is fast ;)

mylungsarempty

6:24 am on Oct 16, 2003 (gmt 0)

10+ Year Member



you guys rock.

isorg

2:17 pm on Oct 17, 2003 (gmt 0)

10+ Year Member



I would definitely store it in the database as a number rather than a textual description of the date. With a number you can

(1) display it in any way you want
(2) if you later decide to change the way you want to display it, this is very straightforward
(3) it is so much easier to do calculations on the date e.g. if you wanted to say that the user has been a member for x days (e.g. a free trial period maybe) - get the date value (which is represented as the number of seconds from 1 January 1970), minus it from the current date/time to get the number of seconds since signup or
(4) if you wanted to query your database to see who signed up in the last 30 days for example - "select username from members where signupdate > 'x'" .