Time Stamp
Moderator: General Moderators
Time Stamp
Is there any php code I can use to include the date a user submitted his form and add it to the db. Thanks for the help!
-Ace
-Ace
there are a number of ways to do this. personally, i like to create a field in the database that is a bigint. the php function mktime() returns a unix timestamp, and this number can be inserted into the field you just created.
i prefer the field type of bigint versus datetime because the php date() function takes in a unix timestamp, and this makes it all much easier. on the flip side, however, mysql has severl built-in functions for dealing with time, so you may prefer to go that route. in such case set "date_field=now()" in your SQL query.
[edit: yeah, that should be time(), not mktime()]
i prefer the field type of bigint versus datetime because the php date() function takes in a unix timestamp, and this makes it all much easier. on the flip side, however, mysql has severl built-in functions for dealing with time, so you may prefer to go that route. in such case set "date_field=now()" in your SQL query.
[edit: yeah, that should be time(), not mktime()]
Last edited by will on Thu Jul 18, 2002 12:49 am, edited 2 times in total.
I use time() at the begining of the form processing script and then just add the value to the db. Then depending on how you are redisplaying the information you can use the PHP date() to format it.
Code: Select all
/// Get the time
$time = time();
Then insert the $time value into the database.
When you eventually query the database for the value you can use the PHP date formats.
echo date ("m/d/Y", $qryїtime]);You will want to use the DATE_ADD function in MySQL to move forward a certain number of days. I haven't found a PHP function with this ability so I would make it a part of my SQL calls because coding it in PHP will be a little tricky with different day numbers in months and special dates like leap year.
Hope this helps,
Hope this helps,
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
That's called a timestamp and there's a quick explanation of it in the man page for time(). As for what you can do with it now, have a look at PHP's date and time functions and MySQL's.
Mac
Mac
Last edited by twigletmac on Sun Jul 21, 2002 5:54 am, edited 1 time in total.
EricS wrote:<snip> because coding it in PHP will be a little tricky with different day numbers in months and special dates like leap year.
Hope this helps,
no it wouldn't... that's the beauty of the unix timestamp... it's simply the number of seconds since the epoch (january 1, 1970 if i remember correctly).
to increment by 15 days, you would get your unix timestamp and add 1296000 (60 * 60 * 24 * 15). then when you convert it to whatever format you want using date(), the month, leap year, etc will be taken into account.
actually, i'm pretty sure that the mysql datetime field type uses the same unix timestamp, it's just does it all behind the scenes.