Tuesday, August 13, 2013

how to get no of days in the current month(count)?

$da = date('d'); // gets the current day of the month
$mth = date('m');    // gets the current month
$yr = date('Y');   // gets the current year
$daysinmonth = cal_days_in_month(CAL_GREGORIAN,$mth,$yr);
echo $daysinmonth;   // this will echo the total no of days in the current month

now you might also want to use the no of days left in the current month from the current day, here's how that's done:-

$baldays = $daysinmonth - $da;
echo $baldays;    // this would echo out the no of days remaining for the current month to end

how to automatically get the first date of the current month in mysql

there are several ways of doing it. here is how i do it. it just feels simpler this way :)


$mth = date('m');                               // gets the current month
$yr = date('Y');                                   // gets the current year

For example, if i want to run a query to get results between the first day of the current month and today, i would write it like this:-

"SELECT * FROM table WHERE date BETWEEN '$yr-$mth-01' AND CURDATE( )"

Sunday, June 30, 2013

how to change all to UPPERCASE in an input box

for a text box, here's the code.

<input type="text" onblur="this.value=this.value.toUpperCase()" name="" placeholder="all of this will be uppercase" />

Wednesday, May 22, 2013

How to update mysql table ignoring the duplicate fields that are already present

here's how you do it.


INSERT INTO thetable (pageid, name, somefield)
VALUES (1, "foo", "first")
ON DUPLICATE KEY UPDATE (somefield = 'first')
taken from

Update one Mysql table with results from another table on a different database

here's how you update one table with results from another database query.


UPDATE
target_database.target_table A                                //database to be updated-target
INNER JOIN source_database.source_table B     //join source database to target
ON B.ProductID = A.ProductID                          //join fields
SET A.Markup = B.Markup                                         //fields to be updated

Sunday, April 28, 2013

how to find duplicates in two columns of mysql database table

any one column can have duplicates. but both columns together are unique. this is how you find duplicates

select   columnA,
         columnB,
         count(*)
from     table_name
group by columnA,
         columnB
having   count(*) > 1

Monday, January 7, 2013