• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pub date

#1
[eluser]benfike[/eluser]
Hi!

I have an problem..

I have a comment system and I have fields for it.

create_date = when they send the comment.
pub_date = create_date + 3 min

Code:
function submitComment(){
        $create_date = date("Y-m-d H:i:s");
        $text = strip_tags($_POST['text']);
        $data = array(
            
            'status' => 'active',
            'create_date' => $create_date,
            'pub_date' => $create_date+180,
            'user_id' => $_SESSION['user_id'],
            'post_id' => $_POST['post_id'],
            'text' => $text
            
        );

I already trying something like this, but it is dont work. It post 0000-00-00 00:00:00 ..

Help pls.
Thank you in advance.

#2
[eluser]jmadsen[/eluser]
if you echo

Code:
$create_date = date("Y-m-d H:i:s");

you'll see you get a formatted date (ex., "2010-09-26 09:43:41"), so adding 180 to it doesn't make sense.

There are two ways of adding onto dates, generally speaking:

1) convert your time to a timestamp and add 180 to that
2) break your date into its parts with date("Y"),etc; add +180 to the seconds part, then use mktime to turn it back into a formatted date.

Dates are confusing to work with, but worth the time to get comfortable with. Start here http://php.net/manual/en/function.date.php and google a little for one of the many good tutorials on php date adding


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.