Unable to get last friday date in PST time in PHP
up vote
0
down vote
favorite
I am trying to getting last friday date PST time, i am getting 15-11-2018,
Here is my code,
public function getPSTCurrentTime($time=null) {
$dateTime = new DateTime($time, (new DateTimeZone('UTC'))); // get current time as UTC/GMT timezone
$dateTime->setTimezone(new DateTimeZone('PST')); // convert time as PST timezone
return $dateTime;
}
$date = new getPSTCurrentTime('last friday')->format('Y-m-d h:i:s');
The output i am getting was 15-11-2018, But i am expecting output was 16-11-2018
php date datetime
add a comment |
up vote
0
down vote
favorite
I am trying to getting last friday date PST time, i am getting 15-11-2018,
Here is my code,
public function getPSTCurrentTime($time=null) {
$dateTime = new DateTime($time, (new DateTimeZone('UTC'))); // get current time as UTC/GMT timezone
$dateTime->setTimezone(new DateTimeZone('PST')); // convert time as PST timezone
return $dateTime;
}
$date = new getPSTCurrentTime('last friday')->format('Y-m-d h:i:s');
The output i am getting was 15-11-2018, But i am expecting output was 16-11-2018
php date datetime
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to getting last friday date PST time, i am getting 15-11-2018,
Here is my code,
public function getPSTCurrentTime($time=null) {
$dateTime = new DateTime($time, (new DateTimeZone('UTC'))); // get current time as UTC/GMT timezone
$dateTime->setTimezone(new DateTimeZone('PST')); // convert time as PST timezone
return $dateTime;
}
$date = new getPSTCurrentTime('last friday')->format('Y-m-d h:i:s');
The output i am getting was 15-11-2018, But i am expecting output was 16-11-2018
php date datetime
I am trying to getting last friday date PST time, i am getting 15-11-2018,
Here is my code,
public function getPSTCurrentTime($time=null) {
$dateTime = new DateTime($time, (new DateTimeZone('UTC'))); // get current time as UTC/GMT timezone
$dateTime->setTimezone(new DateTimeZone('PST')); // convert time as PST timezone
return $dateTime;
}
$date = new getPSTCurrentTime('last friday')->format('Y-m-d h:i:s');
The output i am getting was 15-11-2018, But i am expecting output was 16-11-2018
php date datetime
php date datetime
asked Nov 19 at 15:23
VijayaKrishna
278
278
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
Try this,
$pst = new DateTimeZone('America/Los_Angeles');
$last_friday = new DateTime('last friday', $pst);
echo $last_friday->format('Y-m-d H:i:s'); // "2018-11-16 00:00:00"
After Comment:
To get the date based on the current timezone, then use date_default_timezone_get
$current_timezone = new DateTimeZone(date_default_timezone_get());
$last_friday = new DateTime('last friday', $current_timezone);
Output:
2018-11-16 00:00:00
I don't to put any Datetimezone, here, the user may login from any where
– VijayaKrishna
Nov 19 at 15:30
In your code, you're already usingDateTimeZone('PST')
– mbharanidharan88
Nov 19 at 15:31
i am converting UTC time zone to PST timezone,
– VijayaKrishna
Nov 19 at 15:33
What is your actual requirement? There is a way if you want to take dates based on the timezone and there is no need to convert toUTC
first
– mbharanidharan88
Nov 19 at 15:36
I am working from india, and my client was america, The difference between time 8 hours between UTC and PST, any user can login according to their time, so i am trying to convert UTC to PST, your method was wrong
– VijayaKrishna
Nov 19 at 15:52
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Try this,
$pst = new DateTimeZone('America/Los_Angeles');
$last_friday = new DateTime('last friday', $pst);
echo $last_friday->format('Y-m-d H:i:s'); // "2018-11-16 00:00:00"
After Comment:
To get the date based on the current timezone, then use date_default_timezone_get
$current_timezone = new DateTimeZone(date_default_timezone_get());
$last_friday = new DateTime('last friday', $current_timezone);
Output:
2018-11-16 00:00:00
I don't to put any Datetimezone, here, the user may login from any where
– VijayaKrishna
Nov 19 at 15:30
In your code, you're already usingDateTimeZone('PST')
– mbharanidharan88
Nov 19 at 15:31
i am converting UTC time zone to PST timezone,
– VijayaKrishna
Nov 19 at 15:33
What is your actual requirement? There is a way if you want to take dates based on the timezone and there is no need to convert toUTC
first
– mbharanidharan88
Nov 19 at 15:36
I am working from india, and my client was america, The difference between time 8 hours between UTC and PST, any user can login according to their time, so i am trying to convert UTC to PST, your method was wrong
– VijayaKrishna
Nov 19 at 15:52
add a comment |
up vote
1
down vote
Try this,
$pst = new DateTimeZone('America/Los_Angeles');
$last_friday = new DateTime('last friday', $pst);
echo $last_friday->format('Y-m-d H:i:s'); // "2018-11-16 00:00:00"
After Comment:
To get the date based on the current timezone, then use date_default_timezone_get
$current_timezone = new DateTimeZone(date_default_timezone_get());
$last_friday = new DateTime('last friday', $current_timezone);
Output:
2018-11-16 00:00:00
I don't to put any Datetimezone, here, the user may login from any where
– VijayaKrishna
Nov 19 at 15:30
In your code, you're already usingDateTimeZone('PST')
– mbharanidharan88
Nov 19 at 15:31
i am converting UTC time zone to PST timezone,
– VijayaKrishna
Nov 19 at 15:33
What is your actual requirement? There is a way if you want to take dates based on the timezone and there is no need to convert toUTC
first
– mbharanidharan88
Nov 19 at 15:36
I am working from india, and my client was america, The difference between time 8 hours between UTC and PST, any user can login according to their time, so i am trying to convert UTC to PST, your method was wrong
– VijayaKrishna
Nov 19 at 15:52
add a comment |
up vote
1
down vote
up vote
1
down vote
Try this,
$pst = new DateTimeZone('America/Los_Angeles');
$last_friday = new DateTime('last friday', $pst);
echo $last_friday->format('Y-m-d H:i:s'); // "2018-11-16 00:00:00"
After Comment:
To get the date based on the current timezone, then use date_default_timezone_get
$current_timezone = new DateTimeZone(date_default_timezone_get());
$last_friday = new DateTime('last friday', $current_timezone);
Output:
2018-11-16 00:00:00
Try this,
$pst = new DateTimeZone('America/Los_Angeles');
$last_friday = new DateTime('last friday', $pst);
echo $last_friday->format('Y-m-d H:i:s'); // "2018-11-16 00:00:00"
After Comment:
To get the date based on the current timezone, then use date_default_timezone_get
$current_timezone = new DateTimeZone(date_default_timezone_get());
$last_friday = new DateTime('last friday', $current_timezone);
Output:
2018-11-16 00:00:00
edited Nov 19 at 15:34
answered Nov 19 at 15:28
mbharanidharan88
4,04332253
4,04332253
I don't to put any Datetimezone, here, the user may login from any where
– VijayaKrishna
Nov 19 at 15:30
In your code, you're already usingDateTimeZone('PST')
– mbharanidharan88
Nov 19 at 15:31
i am converting UTC time zone to PST timezone,
– VijayaKrishna
Nov 19 at 15:33
What is your actual requirement? There is a way if you want to take dates based on the timezone and there is no need to convert toUTC
first
– mbharanidharan88
Nov 19 at 15:36
I am working from india, and my client was america, The difference between time 8 hours between UTC and PST, any user can login according to their time, so i am trying to convert UTC to PST, your method was wrong
– VijayaKrishna
Nov 19 at 15:52
add a comment |
I don't to put any Datetimezone, here, the user may login from any where
– VijayaKrishna
Nov 19 at 15:30
In your code, you're already usingDateTimeZone('PST')
– mbharanidharan88
Nov 19 at 15:31
i am converting UTC time zone to PST timezone,
– VijayaKrishna
Nov 19 at 15:33
What is your actual requirement? There is a way if you want to take dates based on the timezone and there is no need to convert toUTC
first
– mbharanidharan88
Nov 19 at 15:36
I am working from india, and my client was america, The difference between time 8 hours between UTC and PST, any user can login according to their time, so i am trying to convert UTC to PST, your method was wrong
– VijayaKrishna
Nov 19 at 15:52
I don't to put any Datetimezone, here, the user may login from any where
– VijayaKrishna
Nov 19 at 15:30
I don't to put any Datetimezone, here, the user may login from any where
– VijayaKrishna
Nov 19 at 15:30
In your code, you're already using
DateTimeZone('PST')
– mbharanidharan88
Nov 19 at 15:31
In your code, you're already using
DateTimeZone('PST')
– mbharanidharan88
Nov 19 at 15:31
i am converting UTC time zone to PST timezone,
– VijayaKrishna
Nov 19 at 15:33
i am converting UTC time zone to PST timezone,
– VijayaKrishna
Nov 19 at 15:33
What is your actual requirement? There is a way if you want to take dates based on the timezone and there is no need to convert to
UTC
first– mbharanidharan88
Nov 19 at 15:36
What is your actual requirement? There is a way if you want to take dates based on the timezone and there is no need to convert to
UTC
first– mbharanidharan88
Nov 19 at 15:36
I am working from india, and my client was america, The difference between time 8 hours between UTC and PST, any user can login according to their time, so i am trying to convert UTC to PST, your method was wrong
– VijayaKrishna
Nov 19 at 15:52
I am working from india, and my client was america, The difference between time 8 hours between UTC and PST, any user can login according to their time, so i am trying to convert UTC to PST, your method was wrong
– VijayaKrishna
Nov 19 at 15:52
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377741%2funable-to-get-last-friday-date-in-pst-time-in-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown