Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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
Closed 9 years ago.
Improve this question
I'm using this to get the number of days between two dates:
$nbDays = $dateArrival->diff($dateDeparture);
I can use "->format()" if I want to output this to the screen. But how can I transform this into an INT if I want to use the number of days in a multiplication?
diff() returns a DateInterval which has a public days property.
$nbDays = $dateArrival->diff($dateDeparture);
echo $nbDays->days;
The return value of DateTime::diff is a DateInterval. If you look at the documentation, you will see that class has a days field which you can use to get an integer number of days.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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
Closed 9 years ago.
Improve this question
In my database I have a entry_date that is set as a DATETIME type, how do I go about querying the database for a specific day? For example if I have a record with 2013-12-27 16:14:10
and I only really care that I'm getting the record where the 2013-12-27 matches.
Assuming MySQL, use DATE():
Extracts the date part of the date or datetime expression.
SELECT *
FROM tablename
WHERE DATE(datecol) = '2013-12-27'
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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
Closed 9 years ago.
Improve this question
I have, for example the string 2013-12-08 19:55:19 and from this string I want to obtain 19:55. How can I do this in PHP?
You can go parsing the datetime to an object and stuff, or you can simply do:
substr($myString,11,5)
(take 5 characters starting from the 11th character)
Only condition is that your string always has 4 digits for the year. And 2 digits for all other elements. Just like in your OP
Check out strtotime() and date():
echo date('G:i', strtotime('2013-12-08 19:55:19'));
You can use regex:
$str = "2013-12-08 19:55:19";
preg_match("/.*(\d\d\:\d\d)\:\d\d\.*/", $str, $arr);
echo "time: " . $arr[1];
OUTPUT
time: 19:55
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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
Closed 9 years ago.
Improve this question
I want to add the current time when the user has submitted the form in database?
You can get the timestamp with PHP's DateTime->setTimeStamp() method.
For DateTime, use something like this
$date = new DateTime();
$timestamp=$date->format("Y-m-d H:i:s'); //Returns something like 2013-12-7 11:10:14
If you're looking to do this in MySQL as opposed to PHP, use the CURRENT_TIMESTAMP() method
use date() function of php to get the current time.
$adate=date("Y-m-d");
or you can use NOW() in mysql to insert the current time in mysql.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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
Closed 9 years ago.
Improve this question
In my application, the user gives 2 inputs — one is date and the other is time:
$date = date("d-M-Y");
$time=date("h:m:s");
How can I calculate a time stamp from these two variables in PHP?
actually i take the date form date picker and time from time oicker.....
If you want time stamp then use this
echo strtotime($date.' '.$time);
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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
Closed 9 years ago.
Improve this question
How do I get and set a variable to the Eastern time zone and then use it in an "if" statement?
In one of my table I have a datetime column called gameEasternTime. Values are listed like so "2013-09-22 20:30:00"
I need to show a html div only if the Eastern time is after the time listed in my gameEasternTime column.
if ( $easternTime > schedule[gameEasternTime] ) {
echo ' <div> ';
}
Use date_default_timezone_set('America/New_York') and DateTime::format . Yes, those are links.