www.webdeveloper.com
Results 1 to 4 of 4

Thread: Need help with creating a date function

  1. #1
    Join Date
    Apr 2010
    Posts
    62

    Need help with creating a date function

    Hello! I don't even know where to begin with this script as my novice knowledge of PHP is not nearly advanced enough.

    I need a function to check if $vip['expires'] is either today, or if it has passed already. If it is infact today or if it has passed already, I want it to perform the following

    PHP Code:
            $nextgift date('F j, Y'strtotime("+1 month"));
        
    $changerb mysql_query("update usr_vip set nextgift = '$nextgift' where userid = '$user[id]'"); 

  2. #2
    Join Date
    Apr 2010
    Posts
    213
    Mysql has a very convenient datediff() function that lets you do exactly what you want right in the sql query. There are subtle differences in the syntax depending on how the dates are represented in the database (date, date_time, timestamp, etc.), so I can't tell you the precise code but the relavent information is here:
    http://dev.mysql.com/doc/refman/5.1/...functions.html

    Good luck.

  3. #3
    Join Date
    Apr 2010
    Posts
    62
    Thank you! I believe this will work - I'm going to test it when I have a chance

    PHP Code:
    <? 
    $today 
    date("F j, Y");
    $check SELECT DATEDIFF('$vip[date]','$today');
        if(
    $check >= 0) { 
        
    $nextgift date('F j, Y'strtotime("+1 month")); 
        
    $changerb mysql_query("update usr_vip set nextgift = '$nextgift' where userid = '$user[id]'");
        } 
        
    ?>

  4. #4
    Join Date
    Apr 2010
    Posts
    213
    You might be able to do it with something as simple as this:

    Code:
    <?
    $id = $user['id'];
    $sql = "UPDATE usr_vip SET nextgift = DATE_ADD(CURDATE(), INTERVAL 1 MONTH) ";
    $sql .=		"WHERE ((userid='$id') AND (nextgift <= CURDATE()))";
    $changerb = mysql_query($sql);
    if (!($changerb)) {
    	die('Whoops... I did not understand the question :(');
    }
    while ($row = mysql_fetch_assoc($changerb)) {
    	echo $row['username'];
    	echo " gets a ";
    	echo $row['usergift'];
    	echo " today\n";
    }
    ?>
    Much luck .

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles