c-o-d-e Posted November 23, 2009 Share Posted November 23, 2009 How would I get the current year? I can get the current time, but Year, I think will be different. The year should be the full year eg: 2009. Not 09. $year = //Get the current year $query = mysql_error("UPDATE Users SET Used = '$year' WHERE username = '$username'") or trigger_error('Query failed: '. mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/182677-how-would-i-get-the-current-year/ Share on other sites More sharing options...
ShadowIce Posted November 23, 2009 Share Posted November 23, 2009 <?php echo date('l, F jS Y h:i:s A'); ?> Your welcome! Quote Link to comment https://forums.phpfreaks.com/topic/182677-how-would-i-get-the-current-year/#findComment-964140 Share on other sites More sharing options...
PFMaBiSmAd Posted November 23, 2009 Share Posted November 23, 2009 It's almost always best and faster to perform an operation using mysql funcitons directly in a query - $query = mysql_error("UPDATE Users SET Used = YEAR(CURDATE()) WHERE username = '$username'") or trigger_error('Query failed: '. mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/182677-how-would-i-get-the-current-year/#findComment-964143 Share on other sites More sharing options...
c-o-d-e Posted November 23, 2009 Author Share Posted November 23, 2009 Can you explain what all that does ShadowIce? I notice it has time, it should only have the Year. So when updating the database, the value would become "2009" etc. PFMaBiSmAd, would YEAR(CURDATE()) display the year, or the whole date? Thanks for the replies. Quote Link to comment https://forums.phpfreaks.com/topic/182677-how-would-i-get-the-current-year/#findComment-964144 Share on other sites More sharing options...
PFMaBiSmAd Posted November 23, 2009 Share Posted November 23, 2009 What the YEAR() and CURDATE() functions do can be found in the documentation - http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html Quote Link to comment https://forums.phpfreaks.com/topic/182677-how-would-i-get-the-current-year/#findComment-964149 Share on other sites More sharing options...
ShadowIce Posted November 23, 2009 Share Posted November 23, 2009 It returns the time followed by the date. I'll edit it so it returns only the date ^^ <?php echo date('l, F jS Y'); ?> try that ^^ Quote Link to comment https://forums.phpfreaks.com/topic/182677-how-would-i-get-the-current-year/#findComment-964150 Share on other sites More sharing options...
c-o-d-e Posted November 23, 2009 Author Share Posted November 23, 2009 Ok thank you. How do I solve this topic, I cant find the solve button. Quote Link to comment https://forums.phpfreaks.com/topic/182677-how-would-i-get-the-current-year/#findComment-964153 Share on other sites More sharing options...
ShadowIce Posted November 23, 2009 Share Posted November 23, 2009 Try renaming the title maybe ^^ Quote Link to comment https://forums.phpfreaks.com/topic/182677-how-would-i-get-the-current-year/#findComment-964154 Share on other sites More sharing options...
PFMaBiSmAd Posted November 23, 2009 Share Posted November 23, 2009 The 'topic solved' modification has yet to be installed in the upgraded forum software. Quote Link to comment https://forums.phpfreaks.com/topic/182677-how-would-i-get-the-current-year/#findComment-964158 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.