Pages

Showing posts with label current. Show all posts
Showing posts with label current. Show all posts

Sunday, September 22, 2013

PHP-Find current quarter for genarating quarterly payments etc.

    $firstday1=date("Y-1-1 00:00:00");
        $lastday1=date("Y-3-31 23:59:59");
        $firstday2=date("Y-4-1 00:00:00");
        $lastday2=date("Y-6-30 23:59:59");
        $firstday3=date("Y-7-1 00:00:00");
        $lastday3=date("Y-9-30 23:59:59");
        $firstday4=date("Y-10-1 00:00:00");
        $lastday4=date("Y-12-31 23:59:59");
        $today = time();
        if( (strtotime($firstday1) <= $today) && ($today<= strtotime($lastday1)))
        {
            $qtr=1;
        }
        elseif( (strtotime($firstday2) <= $today) && ($today <= strtotime($lastday2)))
        {
            $qtr=2;
        }
        elseif( (strtotime($firstday3) <= $today) && ($today <= strtotime($lastday3)))
        {
            $qtr=3;
        }
        elseif( (strtotime($firstday4) <= $today) && ($today <= strtotime($lastday4)))
        {
            $qtr=4;
        }
        echo $qtr;

Sunday, August 18, 2013

Cakephp-Refresh Auth Session information after a database change of current user

In order to update current user logged in Auth Session after a database change in his information in Users Table use the following command

$userid=$this->Auth->user('id');

$this->Session->write('Auth',$this->User->read(null,$userid));

That's it and your auth session is updated..

This is usually done once a user updates his information....

Wednesday, July 17, 2013

Amazon S3-RequestTimeTooSkewed The difference between the request time and the current time is too large

Recently while working on a Project which had a hosting on Amazon Cloudfront, Storage on S3 and Streaming from Amazon EC2.I came across an issue which went ok initially but became a 2 day R&D Topic for my team after a server shutdown and Reset...

While requesting bucket I got a strange error from Amazon

"RequestTimeTooSkewed The difference between the request time and the current time is too large"

I checked everything from security credentials to bucket name finally going to Amazon Support where I came to knew that i was the fault of my system clock.

Our Systems must sync to NTP-Network Time Protocol in order to sync with Amazon Cloud Services..

My server

Centos which is redhat/suse based

Here is how i resolved the same

First and foremost I installed ntp again to be on safer side and make sure every stone in path was carved to needs

Install NTP
Yum install ntp

Check from config NTP is On
Chkconfig ntpd on

If everything is going well without any warnings till now its time to finalize

Sync Server time with amazon ntp

You have to check by trying to access your bucket and adding file to it after each and every sync with following servers..its like hit and try depending on your region.

ntpdate -u 0.amazon.pool.ntp.org
ntpdate -d 0.amazon.pool.ntp.org

ntpdate -u 1.amazon.pool.ntp.org
ntpdate -d 1.amazon.pool.ntp.org

ntpdate -u 2.amazon.pool.ntp.org
ntpdate -d 2.amazon.pool.ntp.org

ntpdate -u 3.amazon.pool.ntp.org
ntpdate -d 3.amazon.pool.ntp.org

That's it that solved my issue out

Tuesday, July 3, 2012

Submitting current timestamp in cakephp

To Submit Current timestamp in cakephp use

DboSource::expression('NOW()');

example

$this->data['SomeModel']['your_datetime_field'] = DboSource::expression('NOW()');
$this->Model->save($this->data);