Friday 20 March 2020

Easiest Way To Change Date From One Timezone To Any Another Timezone | PHP And MYSQL | CONVERT_TZ


Code :-
<style type="text/css">
    body {
  font-family: Arial, Helvetica, sans-serif;
}
</style>
<body>
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'test';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass,$dbname);

if(! $conn ) {
   die('Could not connect: ' . mysqli_error());
}
else
{
    echo "DATABASE CONNECTED<br/>";
}

//CONVERTING TIME FROM NEW YORK(USA) -> KOLKATA(INDIA)
//FROM = NEW YORK
// TO = KOLKATA
$from_exact_date_time='2020-02-15 09:00:00';
$from_timezone=new DateTimeZone('America/New_York');
$from_datetime=new DateTime('now',$from_timezone);
$from_format=$from_datetime->format('P');
echo "New York format : ".$from_format."<br/>";

$to_timezone=new DateTimeZone('Asia/Kolkata');
$to_datetime=new DateTime('now',$to_timezone);
$to_format=$to_datetime->format('P');
echo "Kolkata format : ".$to_format."<br/>";

$query="SELECT CONVERT_TZ('".$from_exact_date_time."','".$from_format."', '".$to_format."') as converted_date";
$data=mysqli_query($conn,$query);

$output=mysqli_fetch_array($data);

echo "NEW YORK DATE/TIME IS : ".$from_exact_date_time."<br/>";
echo "KOLKATA DATE/TIME IS  : ".$output['converted_date'];


?>
</body>
------------------------------------------------
Please avoid or flag spams/hateful comments. And do not spam. Enjoy :)
------------------------------------------------
World Time Buddy :-
https://www.worldtimebuddy.com/

List of timezone : -
https://www.php.net/manual/en/timezones.php

Code Link : -

Subscribe my Channel:-
http://www.youtube.com/user/SanketRooney?sub_confirmation=1

Facebook Page:-
https://www.facebook.com/UnpossibleNS

Twitter Account:-
https://twitter.com/UnpossiblePOG

Blog :-
https://unpossiblepog.blogspot.in/
------------------------------------------------

Hey guys, this is UNPOSSIBLE POG.
In this video, I shall tell you the easiest way to convert date-time from one timezone to any other timezone using PHP and mysql.
In this example I will be converting NEW YORK time to KOLKATA time.
There is a website called “worldtimebuddy” (NOT SPONSORED) which will tell you exact time difference between two timezones.
Link in the description.
I am adding kolkata time and if you click on it, you will see that when in NEW YORK, the date-time is 15th of march 2020 2:00AM, at that time in kolkata, the time is 15th of marth 2020 11:30 AM.
Moving back to code I already added a code of database connection of MYSQLI.
In our code, FROM is NEW YORK and TO is KOLKATA.
First we shall get timezone.
In PHP manual, you will get all the available timezone list. Search for desired timezone.
Then in code, we shall get datetime of that timezone.
It’s link is also given in description.
Then get the difference format.

Same thing we have to do for “TO Timezone” that is, for KOLKATA.
Lets verify.
Remember that those formats are based on UTC.
If you want to convert from UTC then the format is always +00:00.
Then we write an SQL query, there is a function in query called CONVERT_TZ with 3 arguments.
1st argument is the time that you want to convert.
2nd argument is the format of that date, in your case, it is NEW YORK’s format.
3rd argument is the format of timezone that we want to convert.
If everything is correct, then the should be 15 march 2020 : 11:30 AM.
Lets try another date-time.
If in new york the time is 9 AM, then in kolkata it should be 18:30 of same date.
Required links are given in the description.
Thanks for watching. 
Don’t forget to like, share and subscribe.

Saturday 7 March 2020

Google Sheet API | Part 1 | Linux Only | Connect And Display Sheet Data ...




Download VENDOR Folder (Only for PHP version 7.2+): https://unpossiblepog.com/research-and-development/php/Vendor-Folder-For-Google-Sheet-Drive-Calendar-With-PHP-Version-7.2-And-Onward

Please avoid or flag spams/hateful comments. And do not spam. Enjoy :)
------------------------------------------------
Social Media Links :-

Subscribe my Channel:-
http://www.youtube.com/user/SanketRooney?sub_confirmation=1

Facebook Page:-
https://www.facebook.com/UnpossibleNS

Twitter Account:-
https://twitter.com/UnpossiblePOG

Blog :-
https://unpossiblepog.blogspot.in/
------------------------------------------------

Hey guys, this is UNPOSSIBLE POG.
In this video, I shall tell you how to connect connect xampp PHP with google spreadsheet.
In first part, I shall show you how to display data on browser.
There are few requirements that your should have.
1st is to use linux OS. Most preferable is the operating system from Debian Family.
If you want to know how to install and use PHP in LINUX, then tutorial video’s link is given in description.
Now lets get started, go to google and search google spreasheet api php.
Go inside this link, “developer.google.com"
In latest edition of this link, they improved some steps to make integration easier.
Now it says you require php version more than 5.4.
Go to htdocs location.
Create a new folder.
Change it’s persmission to write inside it.
Open the IDE, and assign the folder in it. I prefer sublime text.
Open it in terminal.
now install composer by using this command.
“sudo apt-get install composer”
As you can see I already installed it.
Go to website and enable your google sheet api credentials.
Download it’s configuration.
Copy-paste it in your new created folder which is in htdocs. in my case its google_sheet.
Now we shall run provided command in folder’s terminal.
It may take more than 1 minute because the command is downloading  composer files from google server which are must to run the API.
Copy paste the code in newly created file.
Make sure to close PHP tag.
Now here, you have to make many changes.
First, remove underscore-readonly text from scope.
Add DIR before those two file locations.
Now, by default, google provided some default spreadsheet link which is common for multiple people but we don’t want that so create a new spreadsheet.
Now copy its id which is after D-slash upto another slash, and paste it in code.
Now each spreadsheet has it’s own name, which is at the left corner.
The name is sheet1, so type it in range variable.
And also column are available from A to C.
Lets first run it in terminal because we are going to create a secret key for security purpose.
Well, I forgot to add slash there.
Lets return it.
Now they provide a link, copy it and paste it in browser’s url.
Login into email ID.
Click on advance then go to quickstart unsafe.
Allow access, and copy paste this code in terminal.
There is another mistake that I have made.
Oh yaa, the sheet name was incorrect. Make sure that you should type sheet’s name before exclaimation sign.
Rerun it.
Umm, the output did come but I think that I was jumping on 5th column but in excel sheet there are only 3 columns so make sure that, you only give column number up to maximum available columns in spreadsheet.
 Now to run this code in browser, just comment those lines and open that page in browser.


Required links are given in the description.
Thanks for watching.
Don’t forget to like, share and subscribe.