Carlos Roque Code Hints, Examples and more

16Dec/102

Web Colors Previewer

Have you ever needed to see what a web color like #2a3f43 looks like?

So did i that is why  I made this page Web color previewer
just type the number in the preview box and you will get a box with the color you typed.

If you input a new value the previous one is saved and displayed in a second box labeled previous
just make sure not to type the '#' all you need is the hex values

if you are curious about the code here it is:

13Dec/100

Delete expired entries in MYSQL

For those who want to delete items in a MySQL database based on a date field  the process is very easy.

First of all you need a DATE field, for example a coupon expiration date. the data is saved in the following format: YYYY-MM-DD

Then all you need to delete older items is this:

DELETE FROM coupons WHERE expiration < '2010-12-03'

make sure that your date is set between single quotes ( ' ) if you don't then MySql will treat this as an arithmetic operation 2010 - 12 - 03 =  1995

you can use the php function date to generate a time stamp for today

$today = date("Y-m-d"); // will output something like 2010-12-03

or for yesterday you could use something like

$yestday = date("Y").'-'.date("m").'-'. date("d")-1;

you can subtract an integer to either thedate("Y") or date("m") to go back on years or months

Filed under: MySQL, PHP No Comments