Skip to content
Advertisement

Tag: datetime

How to get total time from several date ranges in php

I have several date ranges in form of DateTime $begin, DateTime $end. Those ranges can overlap in every possible way: etc. What I am trying to do is to get length (in seconds or DateInterval) of those ranges between start of the first one and the end of the latest one (fourth in the case above), excluding regions not covered

Find difference between two datetimes and format at Y-m-d H:i:s

I’m trying to get the difference between two datetimes and return it as a datetime. I’ve found examples using diff but I can’t seem to get it right. However $totaltime logs 0000-00-00 00:00:00 to my DB. Is this because I’m not formatting my totaltime variable? Answer I’m not sure what format you’re looking for in your difference but here’s how

Date and time in Greek

I’m currently using a website to get the time in Athens: $d = new DateTime(“now”, new DateTimeZone(“Europe/Athens”)); echo $d->format(“l, d M Y”); But I would like the date to be displayed in …

Add six months in php

I’m trying to get the month, six months out from the current date. I’ve tried using: date(‘d’, strtotime(‘+6 month’, time())); But it doesn’t seem to work, always returns 01. Is there a better way to do this? Thank you! Answer I find working with DateTime much easier to use: or or in PHP version 5.4+

Add ‘x’ number of hours to date

I currently have php returning the current date/time like so: What I’d like to do is have a new variable $new_time equal $now + $hours, where $hours is a number of hours ranging from 24 to 800. Any suggestions? Answer You may use something like the strtotime() function to add something to the current timestamp. $new_time = date(“Y-m-d H:i:s”, strtotime(‘+5

Adding 1 hour to time variable

I have a time to which I want to add an hour: I’ve tried: But none of the above work. Answer Worked for me.. Explanation: strtotime(’10:09′) creates a numerical timestamp in seconds, something like 1510450372. Simply add or remove the amount of seconds you need and use date() to convert it back into a human readable format. time() also creates

Getting first / last date of the week

Is it possible to get the first / last date of a week using PHP’s Relative Date Time format? I’ve tried to do: As you can see it doesn’t output the correct dates. According to the docs this should be possible if I’m correct. Am I doing something terrible wrong? EDIT I need to use PHP’s DateTime for dates in

Advertisement