PHP date() returns time wrong [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
When using PHP to do time() and store it in a MySQL server and then retrieve it,
when I try to convert it into seconds, it returns strange results.
1386787112 = 35 seconds ago (What my PHP says)
1386787112 was actually 1 second ago (What my current time says).
$da = date("s",1386787112);
This code is meant to returns the current time in second but it only updates if the time is bigger than 60 seconds. Am I doing something wrong?

Using the time() function will do what you're looking for. It's in fact defined just like your requirements.
Now, if you wanted seconds ago you could then use the time() function to do that:
$secs = time() - dbTimeValOfRecord;

Related

convert time to Unix Time stamp [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I need to convert the following date in to Unix format using php code.
2014-06-10T11:05:10.723Z to Unix?
The reason this has so many downvotes is it takes a single in-built function to change a Date to a timestamp, using a single Google search to find.
echo strtotime("2014-06-10T11:05:10.723Z");
Outputs:
1402398310

Is there a way to round up a fraction in PHP even if it's less than half (.499... or lower)? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
In some PHP script, I have a number 5.0000001 that must be rounded to 6.0. Is there a way to round any fractional number greater than 5.0 up to 6.0? (Even if the fraction is less than .5)
The ceil mathematics function in many languages does the opposite of truncation which takes any number that's not a whole number and rounds it up to the proceeding whole number no matter the size of the decimal.
You can also find out more from the php website : http://us3.php.net/ceil
You are looking for PHPs ciel command.

Passing parameter back to the same PHP file [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I have two PHP files: A.php and B.php. A passes $id to B using POST and B can get $id the first time but I need to jump back to B again using Header. This time the parameter gets lost.
How can I pass the parameter when I use Header to jump back?
You must Use $_REQUEST instead of $_POST so it will work in both case . and when you use header to jump back again use query string with same name.
you can pass id variable in the query string when you redirect.

How to compare two timestamps without seconds? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have two timestamps: one from time() function, other selects user in front-end. I need to compare this two timestamps, but ignore the seconds or set it to 00. What is the proper way to do this?
Had some time for an example:
$nr = 1111111122;
$nr = substr($nr, 0, strlen($nr)-2) . "00";
echo strtotime(date('Y-m-d H:i:00', time()));

Can't make cookies expire [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I'm trying to make a cookie expire, I've saw the code that does it, and I've done it already.
So, what I've done already was making the expire date like this time() - 10 this would make the cookie time limit expire immediately, but I can't seem to make it work.
$number_of_days = 30 ;
$date_of_expiry = time() + 60 * 60 * 24 * $number_of_days ;
setcookie( "userlogin", $user_hash, $date_of_expiry, "/" ) ;
This should work:
setcookie("cookie_name", "", time()-3600);
If that does not work, you have any output before, you have to call it before any echo or html output. Otherwise the headers will be already sent and you can't change any cookie information.

Categories