Re: [PHP-DB] Date calculation from MySql table
Something like this should work. $today = mktime(0, 0, 0, date("m"), date("d"), date("Y")); $tomorrow = mktime(0, 0, 0, date("m"), date("d") + 1, date("Y")); $sql = "SELECT COUNT(*) FROM table WHERE regdate BETWEEN {$today} AND {$tomorrow}"; $thismonth = mktime(0, 0, 0, date("m"), 1, date("Y")); $nextmonth = mktime(0, 0, 0, date("m") + 1, 1, date("Y")); $sql = "SELECT COUNT(*) FROM table WHERE regdate BETWEEN {$thismonth} AND {$nextmonth}"; $thisyear = mktime(0, 0, 0, 1, 1, date("Y")); $nextyear = mktime(0, 0, 0, 1, 1, date("Y") + 1); $sql = "SELECT COUNT(*) FROM table WHERE regdate BETWEEN {$thisyear} AND {$nextyear}"; HOWEVER, consider to use the mysql date functions instead of a unix timestamp. A. Joseph wrote: I want to calculate the registed users today Also total users this week Total users this month Total users this year The Mysql table has a row of INT(11) with time() value inserted. I did something like this $today = strtotime("+1 day") Then $sql = "SELECT COUNT(*) FROM table WHERE dateReg <= $today"; Same with year/months also, only I use strtotime("+1 week) for a week, strtotime("+1 month) for a month, Can someone help me with this calculation? On 4/7/08, Bruno Lustosa <[EMAIL PROTECTED]> wrote: On Mon, Apr 7, 2008 at 2:42 PM, Dee Ayy <[EMAIL PROTECTED]> wrote: I was thinking of using output buffering and then making 1 call to utf8_encode, but I think a better question is, how do I stop using utf8_encode completely? If all components are using utf-8, you should have no problems with charsets at all. By all components, I mean: - Script files in utf-8; - Database in utf-8; - Database connection using utf-8; - Content-type header set to utf-8. With all these, you're free of charset hell, and can enjoy the beauty of utf-8 completely without problems. The rendered view I see in Firefox 2.0.0.12 is a question mark "?" where the French character should have appeared. If I use utf8_encode, the character appears as it should. Question mark means the character is not utf-8. Check where it comes from. Might be the database or the way you are connecting to it. I don't know much about mysql, I use postgresql. With it, you just have to call pg_set_client_encoding() to make the connection in utf-8 mode, and "create database with encoding='unicode'" to set up a database using utf-8. Luckily I'm on PHP 4.3.10, so I can't see what mb_check_encoding would report -- if that would even help normally. Shouls upgrade to PHP 5. PHP 4 is way out of date, is not getting updates anymore, and will not even get security bugfixes after august 8th. It's been almost 4 years since PHP 5 was released. http://www.php.net/archive/2007.php Check the PHP 4 end of life announcement. -- Bruno Lustosa <[EMAIL PROTECTED]> ZCE - Zend Certified Engineer - PHP! http://www.lustosa.net/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Date calculation from MySql table
I want to calculate the registed users today Also total users this week Total users this month Total users this year The Mysql table has a row of INT(11) with time() value inserted. I did something like this $today = strtotime("+1 day") Then $sql = "SELECT COUNT(*) FROM table WHERE dateReg <= $today"; Same with year/months also, only I use strtotime("+1 week) for a week, strtotime("+1 month) for a month, Can someone help me with this calculation? On 4/7/08, Bruno Lustosa <[EMAIL PROTECTED]> wrote: > On Mon, Apr 7, 2008 at 2:42 PM, Dee Ayy <[EMAIL PROTECTED]> wrote: > > I was thinking of using output buffering and then making 1 call to > > utf8_encode, but I think a better question is, how do I stop using > > utf8_encode completely? > > If all components are using utf-8, you should have no problems with > charsets at all. By all components, I mean: > - Script files in utf-8; > - Database in utf-8; > - Database connection using utf-8; > - Content-type header set to utf-8. > With all these, you're free of charset hell, and can enjoy the beauty > of utf-8 completely without problems. > > > The rendered view I see in Firefox 2.0.0.12 is a question mark "?" > > where the French character should have appeared. If I use > > utf8_encode, the character appears as it should. > > Question mark means the character is not utf-8. Check where it comes > from. Might be the database or the way you are connecting to it. I > don't know much about mysql, I use postgresql. With it, you just have > to call pg_set_client_encoding() to make the connection in utf-8 mode, > and "create database with encoding='unicode'" to set up a database > using utf-8. > > > Luckily I'm on PHP 4.3.10, so I can't see what mb_check_encoding would > > report -- if that would even help normally. > > Shouls upgrade to PHP 5. PHP 4 is way out of date, is not getting > updates anymore, and will not even get security bugfixes after august > 8th. It's been almost 4 years since PHP 5 was released. > > http://www.php.net/archive/2007.php > > Check the PHP 4 end of life announcement. > > -- > Bruno Lustosa <[EMAIL PROTECTED]> > ZCE - Zend Certified Engineer - PHP! > http://www.lustosa.net/ > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- I develop dynamic website with PHP & MySql, Let me know about your site -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Date Calculation
Since you mentioned MYSQL, I'm assuming you have some sort of database query in mind. For instance, finding dates in a date field in a table in which 14 days from that field date is significant. For instance, the following locates records whose records contain date fields less than 14 days from today: SELECT * FROM mytable WHERE mydate < DATE_ADD(now(), INTERVAL 14 DAY); -Original Message- From: Ben S. [mailto:[EMAIL PROTECTED]] Sent: Monday, November 12, 2001 11:49 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] Date Calculation How do you get the date that is 14 days from today's date? I can get that date with mysql monitor but PHP. I am using PHP4 and MySQL. I have tried many things but nothing works. Does anyone give me a help? Thank you. Ben -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Date Calculation
in PHP, coming out in yyy-mm-dd date("Y-m-d", mktime(0,0,0, date("m"), date("d")+14, date("Y")); untested, so please test it - this will ignore hours, minutes, seconds (the leading 3 0's) and make a timestamp using mktime for this month, this day + 14, this year, then return it formatted as yyy-mm-dd HTH Beau // -Original Message- // From: Ben S. [mailto:[EMAIL PROTECTED]] // Sent: Tuesday, 13 November 2001 1:49 PM // To: [EMAIL PROTECTED] // Subject: [PHP-DB] Date Calculation // // // How do you get the date that is 14 days from today's date? // I can get that date with mysql monitor but PHP. I am using // PHP4 and MySQL. I // have tried many things but nothing works. // Does anyone give me a help? // // Thank you. // Ben // // // // -- // PHP Database Mailing List (http://www.php.net/) // To unsubscribe, e-mail: [EMAIL PROTECTED] // For additional commands, e-mail: [EMAIL PROTECTED] // To contact the list administrators, e-mail: // [EMAIL PROTECTED] // -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Date Calculation
How do you get the date that is 14 days from today's date? I can get that date with mysql monitor but PHP. I am using PHP4 and MySQL. I have tried many things but nothing works. Does anyone give me a help? Thank you. Ben -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Date calculation
How do you get the date that is 14 days from today's date. I am using PHP4 and MySQL. I can get that date with MySQL monitor but php. I have tried many things but nothing works. Does anyone give me a help? Thank you. Ben -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]