Thursday, June 13, 2013
Friday, February 15, 2013
Function to get the last day (saturday) of current week
/**
* Function to get the last day (saturday) of current week
*
* @return string
*/
function get_week_end_date()
{
$format = 'M d, Y';
// if today is saturday, return today's date
if (date('N') === 7)
{
return date($format);
}
else
{
// return next saturday's date
return date($format, strtotime('next saturday'));
}
}
Thursday, September 6, 2012
Get Days of the Week
This function can be used to get the days of the week:
Output of this function will be:
function get_week_days()
{
$timestamp = strtotime('monday this week');
$week_days = array();
for ($i = 1; $i <= 7; $i++)
{
$day = array();
$day['name'] = strftime('%A', $timestamp);
$day['short_name'] = strftime('%a', $timestamp);
$week_days[$i] = $day;
$timestamp = strtotime('+1 day', $timestamp);
}
return $week_days;
}
Output of this function will be:
Array
(
[1] => Array
(
[name] => Monday
[short_name] => Mon
)
[2] => Array
(
[name] => Tuesday
[short_name] => Tue
)
[3] => Array
(
[name] => Wednesday
[short_name] => Wed
)
[4] => Array
(
[name] => Thursday
[short_name] => Thu
)
[5] => Array
(
[name] => Friday
[short_name] => Fri
)
[6] => Array
(
[name] => Saturday
[short_name] => Sat
)
[7] => Array
(
[name] => Sunday
[short_name] => Sun
)
)
Hope this function will be useful to list the days of the week somewhere in your projects.
Happy coding..:)
Monday, April 16, 2012
Date Range Checking Using PHP
1)
/**
* Function to check if a date is within a date range
* Returns true if date falls within startDate and startDate
*
* @param timestamp $date
* @param timestamp $startDate
* @param timestamp $startDate
*
* @return boolean
*/
public function isDateInRange($date, $startDate, $endDate)
{
return (($date >= $startDate) && ($date <= $endDate));
}
2)
/**
* Function to check if a date range falls within another date range
*
* @param timestamp $startDate1 first date range startDate
* @param timestamp $endDate1 first date range endDate
* @param timestamp $startDate2 second date range startDate
* @param timestamp $endDate2 second date range endDate
*
* @return boolean
*/
public function isDateRangeInDateRange($startDate1, $endDate1, $startDate2, $endDate2)
{
return ($this->isDateInRange($startDate2, $startDate1, $endDate1) ||
$this->isDateInRange($endDate2, $startDate1, $endDate1));
}
/**
* Function to check if a date is within a date range
* Returns true if date falls within startDate and startDate
*
* @param timestamp $date
* @param timestamp $startDate
* @param timestamp $startDate
*
* @return boolean
*/
public function isDateInRange($date, $startDate, $endDate)
{
return (($date >= $startDate) && ($date <= $endDate));
}
2)
/**
* Function to check if a date range falls within another date range
*
* @param timestamp $startDate1 first date range startDate
* @param timestamp $endDate1 first date range endDate
* @param timestamp $startDate2 second date range startDate
* @param timestamp $endDate2 second date range endDate
*
* @return boolean
*/
public function isDateRangeInDateRange($startDate1, $endDate1, $startDate2, $endDate2)
{
return ($this->isDateInRange($startDate2, $startDate1, $endDate1) ||
$this->isDateInRange($endDate2, $startDate1, $endDate1));
}
Friday, March 16, 2012
Get First and Last Date of the Current Week - The MySql Way
First Day of the Week
SELECT DATE_ADD(current_date, INTERVAL(1-DAYOFWEEK(current_date)) DAY) FIRST_DAY_OF_WEEK;
Last Day of the Week
SELECT DATE_ADD(current_date, INTERVAL(7-DAYOFWEEK(current_date)) DAY) LAST_DAY_OF_WEEK;
SELECT DATE_ADD(current_date, INTERVAL(1-DAYOFWEEK(current_date)) DAY) FIRST_DAY_OF_WEEK;
Last Day of the Week
SELECT DATE_ADD(current_date, INTERVAL(7-DAYOFWEEK(current_date)) DAY) LAST_DAY_OF_WEEK;
Monday, June 6, 2011
URL Rewriting
Found a really nice and simple article on URL rewriting using .htaccess. Thought of sharing it :)
Here is it:-
http://www.sicanstudios.com/how-to-remove-php-html-htm-extensions-with-htaccess/
Here is it:-
http://www.sicanstudios.com/how-to-remove-php-html-htm-extensions-with-htaccess/
Monday, January 10, 2011
How to check if script tags are entered in a field
jQuery.validator.addMethod("disableScript", function(text, element) {
return (text.match(/\<\bscript\b/i) || text.match(/\<\/\bscript\b/i))?false:true;
}, "Script tags are not allowed");
And how to use it?? It's very simple.
Just add this method to the list of rules to validate the particular input field.
Example:-
rules: {
first_name: {required: true, disableScript: true},
comment: {disableScript: true}
}
Note:
The JQuery validator plugin js file should be included in the page for this to work.
Subscribe to:
Posts (Atom)