I have a Symfony2 application with a table that contains a date field, whose type is DateTime. I need to get all the entities where that field value is now. If I uses the following code, I get 0 results because Doctrine is comparing the DateTime object. I need to only compare year, month, and day, not hours. How can
Tag: datetime
PHP – Can’t set correct DateTimeZone to DateTime
Background I have a list of events that are set to a certain (UK) time. I want users to see the time of the event in their local time. For example: if an event starts at 20:30 UK time a user from the …
php Object of class DateInterval could not be converted to string
i’ve tried using date_diff and date_create to get a difference from two date that’s already converted to string. here’s the code: and i am getting this error: Answer You need to call DateInterval::format() to display that difference as a string. See the manual for all of the available formatting options.
PHP convert UTC time to local time
Am getting a UTC time from my server like the following format, my requirement is to convert the UTC time to local time. So users can see a user friendly time on their browser based on their timezone. Please help me to solve this issue. Thank you I have tried some methods but not working in my case First Second
Modify microseconds of a PHP DateTime object
I have a PHP DateTime object with microseconds created as follows: How can I modify the microseconds value of $dt, without creating a completely new DateTime instance? Answer You can’t. There are three methods that can modify the value of a DateTime instance: add, sub and modify. We can rule out add and sub immediately because they work in terms
PHP DateTime round up to nearest 10 minutes
I’m retrieving a datetime from a mysql field but I need to round it up to the nearest 10 minutes. For example, If the datetime is 2013-11-06 14:00:01, I’d like to return the time as 6/11/2013 14:10. What’s the easiest way to do this? Any advice appreciated. Thanks. Answer 1) Set number of seconds to 0 if necessary (by rounding
How to calculate the time consumed from start time to end time in php
I want to get the perfect time consumed or the total time from start time to end time: My code: In the code above if $start_time = 11:00:00 PM and $end_date =11:30:00 it gives me the output of 0.5 instead of 30minutes. Is there any appropriate way to do it like that? So if the: or: Regards! Answer Try diff
How to format an UTC date to use the Z (Zulu) zone designator in php?
I need to display and handle UTC dates in the following format: 2013-06-28T22:15:00Z As this format is part of the ISO8601 standard I have no trouble creating DateTime objects from strings like …
How to format a PHP date in .Net DataContractJsonSerializer format?
There is a requirement to send a date inside a JSON post using PHP in this following format /Date(410256000000-0800)/ How do I convert a standard dd-mm-yyyy h:i:s datetime like 01-01-2013 12:00:…
Round datetime to last hour
I tried to look for this but I could not find good example of this what im trying to do. I got datetime values in MySQL database that has to be rounded down when that value is on use. Example, all …