Author Archives: invtr

Sync with nist time during windows startup

I have problem with my old PC. The battery is not working anymore. So time is not saved when PC is off. This is alternative for me to keep the PC time up to date by sync the time with nist time during start up.

First you need to set the nist time in your time setting.
– double click the time on bottom left
– choose internet time
– check the “Automatically synchronize with …”
– choose time.nist.gov from the drop down
– press ok

Create a batch file (.bat) that contains this command
w32tm /resync

and save it in C: (e.g. timesync.bat)

Create short cut of the file in your Start > All programs > Startup

With this every time your computer is turned on, your PC local time will be synced with nist internet time.

How many site does his site receive?

Maybe that’s the question you ask on your competitor’s website? Basically it’s hard to know unless the website’s owner tell you, display the stats on their website or you can get into their system.

But with this tool at least you can estimate how many visitors they receive in a day. I’ve tried with few sites of mine and it come quite close to the real stats.

http://www.sitereport.org/p/domainnamehere.com

Have it a try!

Add xx month or xx day to a date

To add xx day or xx month to a date using this method.

1
2
3
4
5
6
7
8
9
10
11
12
$mktime = explode("-",$rs_loan['datestart']);
 
$x = 5;
 
//to add $x to day
$newdate = date("Y-m-d",mktime(0,0,0,$mktime[1],$mktime[2]+$x,$mktime[0]));
 
//to add $x to month
$newdate = date("Y-m-d",mktime(0,0,0,$mktime[1]+$x,$mktime[2],$mktime[0]));
 
//to add $x to year
$newdate = date("Y-m-d",mktime(0,0,0,$mktime[1],$mktime[2],$mktime[0]+$x));

Append 0’s in front of a running number

Sometimes we need to fix a number to say 5 digits. e.g. 00012. Here’s the code to append the 0’s in front of the numbers so that you can just save the number without 0’s in front in your database.

1
2
$anum = 123;
echo str_pad($anum, 5, '0', STR_PAD_LEFT);

Result will be displayed as 00123

Alternative to explode function (PHP)

When you have a set of string in an array or strings separated by comma (or any other character), you can use these two alternative. I prefer the second one 🙂

1
2
3
4
5
6
7
8
9
10
 
//code with explode
$list = explode(",",$astring);
foreach ($astring as $value) {
  echo $value;
  echo "<br />";
}
 
//code with str_replace
echo str_replace(",", "<br />", $astring);