Time manipulation in PHP [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm curious what will be the output of this code? I can't understand what the time() is for, is that indication for the system time?
I edited the code sorry. This is the REAL code
$testnum = 4053000
$timetest = trim($testnum)
$rawnum = time() - ($timetest * 60);
$diffdate = date('d/m/Y H:i:s', $rawnum);
Thank you in advance!

The time() function returns the current time in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). So what you see is an integer in seconds.
You define your timezone in the PHP.ini

Related

How do I convert DateTime from yyyy-mm-dd hh:mm:ss to yyyymmddThhmmssZ in php [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am trying to convert a given date and time in format ( yyyy-mm-dd hh:mm:ss ) to (yyyymmddThhmmssZ) in php. For example: 2020-07-30 18:30:00 should be 20200730T183000Z. I also want to know if there are any existing/in-built methods to accomplish this?
As others have said in your comments, you can simply do this with the DateTime object
Here's an example:
$date = '2020-07-21 18:50:32';
$obj = new \DateTime('#' . strtotime($date));
echo $obj->format(DATE_RFC3339); // 2020-07-22T01:50:32+00:00
If RFC3339 isn't your preferred format, feel free to pick one from the manual, or build your own
Try it out: http://sandbox.onlinephpfunctions.com/code/3246477b676e17022da799697acf4df375e1fe08

Calculate remaining days of leave - php [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Say:
The start day is January 5 and the end is January 10 and the current date is January 7. I want to output the remaining days which is 3.
I think the easiest method is like this.
$date1 = new DateTime("2015-01-01");
$date2 = new DateTime("2010-02-05");
$diff = $date2->diff($date1)->format("%a");

Store time in database [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Which is the best way to store data which come from the entire world?
I was thinking, for instance, to store the time() without timezone and then convert it every time.
Could be right? Is there a method to detect timezone of a request?
For that you can save a Unix Timestamp in your database.
http://php.net/manual/en/function.time.php
http://dev.mysql.com/doc/refman/5.5/en/datetime.html
Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
So every people have the same timestamp format without a timezone.
Otherwise you have to store a Datetime field and the Timezone and calculate the correct value.

Get my country's date and how to compare dates in php [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need to get my country's current date. Currently my project is getting the user's date.
Here are my questions:
how to get my country's current date?
If I'm running my php site in my localhost (wampp), will I still get my country's current date? (I have an internet connection by the way).
PHP fetches time info from the server (your local system in this case). Then, with date_default_timezone_set() you can set any time zone you need.
Please, try this simple code and see what happens:
America/Montreal:<br>
<?php
date_default_timezone_set("America/Montreal");
echo date("Y/m/d H:i:s", time());
?>
<br>
Asia/Aden: <br>
<?php
date_default_timezone_set("Asia/Aden");
echo date("Y/m/d H:i:s", time());

php mysql want to add 30 days from a feild [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i want to add 30 days from the date $first and the result in $sec to take the data between these days from MySQL
$first=05/02/2014
result as in
$sec= 06/02/2014 in m/d/y format
thank you
try
echo $sec=date('m/d/y',strtotime('+30 days', time($first))); //06/04/14

Categories