September 8, 2008

Calculating date difference more precisely in PHP

I thought that a precise dateDiff() function might be helpful for many of you. The following function calculates the difference of two dates in “day” or “month” or “year” more precisely. This function is production ready and you can use it in any of your application which mainly works with these date difference. I have found it somewhere in web, just forgot the source. Thanks to the unknown author of this excellent function.

function datediff($interval, $datefrom, $dateto, $using_timestamps = false)
{

/*
$interval can be:
yyyy - Number of full years
q - Number of full quarters
m - Number of full months
y - Difference between day numbers
(eg 1st Jan 2004 is "1", the first day. 2nd Feb 2003 is "33".
The datediff is "-32".)
d - Number of full days
w - Number of full weekdays
ww - Number of full weeks
h - Number of full hours
n - Number of full minutes
s - Number of full seconds (default)
*/

if (!$using_timestamps) {
$datefrom = strtotime($datefrom, 0);
$dateto = strtotime($dateto, 0);
}
$difference = $dateto - $datefrom; // Difference in seconds

switch($interval) {
case 'yyyy': // Number of full years
$years_difference = floor($difference / 31536000);
if (mktime(date("H", $datefrom),
date("i", $datefrom),
date("s", $datefrom),
date("n", $datefrom),
date("j", $datefrom),
date("Y", $datefrom)+$years_difference) > $dateto) {

$years_difference--;
}
if (mktime(date("H", $dateto),
date("i", $dateto),
date("s", $dateto),
date("n", $dateto),
date("j", $dateto),
date("Y", $dateto)-($years_difference+1)) > $datefrom) {

$years_difference++;
}
$datediff = $years_difference;
break;

case "q": // Number of full quarters
$quarters_difference = floor($difference / 8035200);
while (mktime(date("H", $datefrom),
date("i", $datefrom),
date("s", $datefrom),
date("n", $datefrom)+($quarters_difference*3),
date("j", $dateto),
date("Y", $datefrom)) < $dateto) {

$months_difference++;
}
$quarters_difference--;
$datediff = $quarters_difference;
break;

case "m": // Number of full months
$months_difference = floor($difference / 2678400);
while (mktime(date("H", $datefrom),
date("i", $datefrom),
date("s", $datefrom),
date("n", $datefrom)+($months_difference),
date("j", $dateto), date("Y", $datefrom)) 7)
{ // Sunday
$days_remainder--;
}
if ($odd_days > 6) { // Saturday
$days_remainder--;
}
$datediff = ($weeks_difference * 5) + $days_remainder;
break;

case "ww": // Number of full weeks
$datediff = floor($difference / 604800);
break;

case "h": // Number of full hours
$datediff = floor($difference / 3600);
break;

case "n": // Number of full minutes
$datediff = floor($difference / 60);
break;

default: // Number of full seconds (default)
$datediff = $difference;
break;
}

return $datediff;
}

September 4, 2008

Configure plug2surf tataindicom's device in Linux














Steps to Configure plug2surf tataindicom's device in Linux
« on: March 09, 2008, 02:31:40 AM »

Hi Folks, These are the steps to achieve the net usage in Linux using the plug2surf

1)Login as Root and execute below command

[root@leo prash]#wvdialconf /etc/wvdial.conf

2)now edit the file /etc/wvdial.conf for only the lines which are in bold, In the opened file if you won't find Stupid Mode = 1 line then add it.

[Dialer Defaults]
Modem = /dev/ttyACM0
Baud = 460800
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
ISDN = 0
Modem Type = USB Modem
Stupid Mode = 1
Phone = #777
Username = internet
Password = internet

Now save this file and make a copy of it in same directory as wvdialback.conf

3)Now in Prompt execute below command

[root@leo prash]#wvdial

After executing this command you will find below kind of o/p

--> WvDial: Internet dialer version 1.54.0
--> Cannot get information for serial port.
--> Initializing modem.
--> Sending: ATZ
ATZ
OK
--> Sending: ATQ0
OK
--> Modem initialized.
--> Sending: ATDT#777
--> Waiting for carrier.
ATDT#777
CONNECT
--> Carrier detected. Starting PPP immediately.
--> Starting pppd at Sun Mar 9 14:31:18 2008
--> pid of pppd:
--> Using interface ppp0
--> pppd: 2
--> pppd: 2
--> pppd: 2
--> pppd: 2
--> pppd: 2
--> local IP address x.y.z.w
--> pppd: 2
--> remote IP address a.b.c.d
--> pppd: 2
--> primary DNS address a.e.f.g
--> pppd: 2
--> secondary DNS address e.f.g.k
--> pppd: 2

Save or copy this info and save it in a file.

4) Now send this process in background
This is the command to do so

press ctrl + z and type bg

5)Now open Network config

[root@leo prash]#system-config-network

Here click on edit copy the local IP address x.y.z.w , for ex i have mentioned alphabets, check the respective nos separated by dots, that you had saved in file.

paste this ip address, in fields
Check static IP Address option must be nabled and under Manual IP settings

Address x.y.z.w
leave subnet mask as it is
Default Gateway address x.y.z.w

Then now press OK

Now open Hosts Tab

and Copy the Primary DNS and Secondary DNS ip address mentioned in the saved file over here, and save it, Goto File -> Save

Then press Activate

Now you are done

Open Firefox Mozilla and use the net Lips sealed

September 3, 2008

Google Chrome .. New web browser by Google

Google has launched new web browser on 3rd sep 2008.



Positive Findings
  • Clean cut and crisp
  • No separate address and search bars
  • Simple download, setup and
  • Love the upper tab browsing
  • More like a Mac than a PC
  • More like an app tool than a browser
  • Intelligent bookmarking
  • You can still use your favourite search engine to search
  • No bulky toolbar - I can see my whole screen
    • But what about all the feature functions of my favourite FF3 sites?
  • Great downloading feature - interactive and functional
  • “Create App Shortcuts” - e.g. create Gmail shortcut on the desktop and launch Gmail without any browser trappings.
Negative things
  • Still can’t access Gmail
  • Some of the older format sites are non-compliant and distorted such as Ecademy.com
  • Many images not loading or only half loading
  • NEED my StumbleUpon toolbar, Diigo and delicious mechanisms….
  • Bugs and glitches already identified