Tag Archives: date

FILTER_SANITIZE vs FILTER VALIDATE, whats the difference – and which to use?

Questions: Currently I’m making sort of calculator-like app in PHP with form as method of input. To secure input i’m using filter_input() function. As filter this function take one of elements from two groups: FILTER_SANITIZE and FILTER_VALIDATE, which one should i use to filter input from form? $number1 = trim(filter_input(INPUT_GET, ‘number1’, FILTER_VALIDATE_FLOAT)); or $number1 =… Read More »

Highlight all dates from now until 2 weeks later

Questions: I have a script where i have a table that contains dates for supplies. Now there are alot of dates +- 600. Now what i want to do is to highligt all dates that will expire from today untill two weeks later or if the date is allready in the past. the table looks… Read More »

If DateTime Object Is Null

Questions: I am returning some search results after form submit. All is working fine, until I get to a field that is SMALLDATETIME and allows NULL. At least one of the returned rows has the field as NULL. As you can see in the code below, when it is not NULL I am converting it… Read More »

creating primary key based on date

Questions: I am trying to create a unique ID for each record based on the date the record is created. Example, if the record is created today, I want the key to be 20101130XX where XX would be a sequential list of numbers such as 01, 02, 03 etc… in case more than one person… Read More »

Load Data Local Infile with Hash and Date Using Set

Questions: I am at wits end on this. I have researched this to death and cannot seem to resolve. I have the following PHP statement: $sqlstatement=”LOAD DATA LOCAL INFILE ‘$temp’ INTO TABLE contacts FIELDS TERMINATED BY ‘,’ LINES TERMINATED BY ‘\r’ IGNORE 1 LINES (@ignore, @ID, @Name, @Email, @Type, @Hash, @Time) SET Date_Update=date(‘Y-m-d’) “; My… Read More »

How to replace a letter in a string with a new letter that will not be updated

Questions: Lets say I have some code: $text = $_POST[‘secret’]; $replaces = array( ‘a’ => ‘s’, ‘b’ => ‘n’, ‘c’ => ‘v’, ‘d’ => ‘f’, ‘e’ => ‘r’, ‘f’ => ‘g’, ‘g’ => ‘h’, ‘h’ => ‘j’, ‘i’ => ‘o’, ‘j’ => ‘k’, ‘k’ => ‘l’, ‘l’ => ‘a’, ‘m’ => ‘z’, ‘n’ => ‘m’,… Read More »

PHP date() shows tomorrow's date

Questions: I have an odd error. If I call: date(“js M”) it shows tomorrow’s date, I don’t know what changed because yesterday that function was working just fine. I haven’t tested anything in production, as far as I can see, it only happens in localhost. I already checked my clock and it is right, is… Read More »

How to get aggregate days from PHP's DateTime::diff?

Questions: $now = new DateTime(‘now’); $tomorrow = new DateTime(‘tomorrow’); $next_year = new DateTime(‘+1 year’); echo “<pre>”; print_r($now->diff($tomorrow)); print_r($now->diff($next_year)); echo “</pre>”; DateInterval Object ( [y] => 0 [m] => 0 [d] => 0 [h] => 10 [i] => 17 [s] => 14 [invert] => 0 [days] => 6015 ) DateInterval Object ( [y] => 1 [m]… Read More »