Archive

Posts Tagged ‘Date’

The difference between MySQL CURDATE() and NOW()

CURDATE() returns the DATE part of the current time.
NOW() returns the date and time portions as a timestamp in various formats, depending on how it was requested

Example

mysql> SELECT NOW(),CURDATE(),CURTIME();
+———————+————+———–+
| NOW() | CURDATE() | CURTIME() |
+———————+————+———–+
| 2012-06-18 14:14:01 | 2012-06-18 | 14:14:01 |
+———————+————+———–+
1 row in set (0.03 sec)

EmailFacebookLinkedInMySpaceDiggTumblrStumbleUponShare
Categories: My SQL Tags: , , , ,

timezone_open

It ia an alias of DateTimeZone::__construct()and it creates new DateTimeZone object
Example

<?php
$date = date_create( ’2007-05-17′);
$timezone = timezone_open ( ‘Australia/Perth’ );
date_timezone_set( $date, $timezone );
$dateTimeZone = date_timezone_get($date);
echo ‘TimeZone is ‘. timezone_name_get($dateTimeZone);
?>

Output

TimeZone is Australia/Perth

EmailFacebookLinkedInMySpaceDiggTumblrStumbleUponShare
Categories: PHP Tags: , , , ,

DateTimeZone::__construct

It creates new DateTimeZone object
Example

<?php
$date = new DateTime(‘now’, new DateTimeZone(‘Asia/Calcutta’));
$time = $date->format(‘H:i’);
echo $time;
?>

Output

17:53

EmailFacebookLinkedInMySpaceDiggTumblrStumbleUponShare
Categories: PHP Tags: , , , ,

timezone_transitions_get

Its an  alias of DateTimeZone::getTransitions() and  returns all transitions for the timezone

 

Example

<?php
echo “<pre>”;
$tz = new DateTimeZone(“Australia/Perth”);
print_r(timezone_transitions_get($tz));
?>

Output

It will list all transitions of the timezone

EmailFacebookLinkedInMySpaceDiggTumblrStumbleUponShare
Categories: PHP Tags: , , , ,

DateTimeZone::getTransitions

It returns all transitions for the timezone
Example

<?php
echo “<pre>”;
$tz = new DateTimeZone(“Europe/London”);
$tzTransitions = $tz ->getTransitions();
print_r(array_slice($tzTransitions, 0, 2));
?>

Output

Array
(
[0] => Array
(
[ts] => -2147483648
[time] => 1901-12-13T20:45:52+0000
[offset] => 3600
[isdst] => 1
[abbr] => BST
)

[1] => Array
(
[ts] => -1691964000
[time] => 1916-05-21T02:00:00+0000
[offset] => 3600
[isdst] => 1
[abbr] => BST
)

)

EmailFacebookLinkedInMySpaceDiggTumblrStumbleUponShare
Categories: PHP Tags: , , , ,

timezone_version_get

It returns the version of the timezonedb
Example

<?php
echo timezone_version_get();
?>

Output

0.system

EmailFacebookLinkedInMySpaceDiggTumblrStumbleUponShare
Categories: PHP Tags: , , , ,

timezone_offset_get

Its an alias of DateTimeZone::getOffset() and returns the timezone offset from GMT
Example

<?php
$dateTime =  date_create(’2000-01-01′);
$dateTimeZone = timezone_open(‘Australia/Perth’);
print_r( timezone_offset_get($dateTimeZone, $dateTime) );
?>

Output

28800


EmailFacebookLinkedInMySpaceDiggTumblrStumbleUponShare
Categories: PHP Tags: , , , ,

DateTimeZone::getOffset

It returns the timezone offset from GMT
Example

<?php
$dateTimeZone = new DateTimeZone(‘Australia/Perth’);
echo $dateTimeZone->getOffset(new DateTime(“2000-01-01″, new DateTimezone( ‘GMT’ )));
?>

Output

28800


EmailFacebookLinkedInMySpaceDiggTumblrStumbleUponShare
Categories: PHP Tags: , , , ,

Switch to our mobile site