Set Time
Tagged with: command, date, Linux, set, time
Tuesday, July 15th, 2008 11:12 PM
Set date and time - MonthDayhoursMinutesYear.Seconds
date 041217002007.00
Set date and time - MonthDayhoursMinutesYear.Seconds
date 041217002007.00
Search files created or changed within 10 days
find /usr/bin -type f -mtime -10
Some date finding commands..
$ date
Mon Mar 10 23:52:08 IST 2008
$ cal
March 2008
Su Mo Tu We Th Fr Sa
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
Create the MySQL format date(YYYY-MM-DD) using the date command
date +%Y-%m-%d
This function will find the difference between two given times. Does PHP already have a native function for that?
//The difference between 2 given time
function dateDifference($day_1,$day_2) {
$diff = strtotime($day_1) - strtotime($day_2);
$sec = $diff % 60;
$diff = intval($diff / 60);
$min = $diff % 60;
$diff = intval($diff / 60);
$hours = $diff % 24;
$days = intval($diff / 24);
return array($sec,$min,$hours,$days);
}
If you just want the day difference…
$diff = strtotime($day_1) - strtotime($day_2) + 1; //Find the number of seconds
$day_difference = ceil($diff / (60*60*24)) ; //Find how many days that is
This can be done using the DATEDIFF function in MySQL 5
[tags]php,code,date,difference,time[/tags]
Javascript code for finding the fourth sunday in any given month.
function findFourthSunday(year,month) {
var fourth_sunday = 0;
var sunday_count = 0;
//There is a really cool solution for this
//forth_sunday = 29 - first_day_of_month
//But the problem is if the first of month is a sunday(first_day_of_month == 0), then there will be a bug. Found the bug in April 2007
for(var i=1;i<31;i++) {
var a_day = new Date(year,month,i);
if(a_day.getDay() == 0) sunday_count++;//'0' means sunday - 1 for monday, etc.
if(sunday_count == 4) {
fourth_sunday = i;
break;
}
}
return fourth_sunday;
}
function init() {
var month_names = new Array("January","February","March","April","May","June","July","Augest","September","October","November","December");
var first_day = ""
var today = new Date();
var year = today.getYear();
year = (year > 2000) ? year : year + 1900;
var month = today.getMonth();
var fourth_sunday = findFourthSunday(year,month);
if(today.getDate() > fourth_sunday) {
month ++;
fourth_sunday = findFourthSunday(year,month);
} else if(today.getDate() == fourth_sunday) {
fourth_sunday = "Today - " + fourth_sunday;
}
var date = fourth_sunday + " " + month_names[month] + ", " + year;
alert(date);
}
window.onload=init;
[tags]javascript,fourth,sunday,calender,month,date,day,code[/tags]