strtotime

Converting birthday in format DDMMMYY to date value in PHP

天大地大妈咪最大 提交于 2019-12-12 10:15:29
问题 I've got bunch of birthdays which are stored in format DDMMMYY. I need to convert those to date values, so i can store those in database. Is there any easy way of telling strtotime function that date must be in the past? <?php $datestring = '22SEP41'; echo date('Y-m-d',strtotime($datestring)); //outputs 2041-09-22, should be 1941-09-22 ?> 回答1: <?php $datestring = '22SEP41'; $matches = []; preg_match('/([0-9]{2})([A-Z]{3})([0-9]{2})/', $datestring, $matches); $prefix = ($matches[3] <= date('y'

php date (“Y/m/d”) is one day off

心不动则不痛 提交于 2019-12-12 04:19:05
问题 if I write date ("Y/m/d"); the result is the current date plus one day. Why is this happening? What can I do to instead get the current date? 回答1: Please check your default time Zone. date_default_timezone_set('America/Bogota'); 回答2: Try with the Time zone <?php date_default_timezone_set("America/New_York"); echo "The time is " . date("h:i:sa"); ?> Try which is your timezone. $timezones = array( 'Pacific/Midway' => "(GMT-11:00) Midway Island", 'US/Samoa' => "(GMT-11:00) Samoa", 'US/Hawaii' =>

Compare current date with a date in d/mm/yyyy format in PHP

六月ゝ 毕业季﹏ 提交于 2019-12-12 04:01:19
问题 What is the best way to check if a given date - a string d/mm/yyyy is a past? When I used strtotime(), it didn't work well, because of non-American notation. Of course I might deal with the dates as strings and compare substrings, but there has to be a better way. if((strtotime('now')-strtotime($date)) > 86400) echo $date; 回答1: Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m

Incorrect results showing on Date conversion in php

不想你离开。 提交于 2019-12-12 03:28:19
问题 $testTime = strtotime("2016-03-03 07:40:45 pm"); echo "final=".$final = DATE("Y-m-d H:i",$testTime);//2016-03-03 19:40 Showing the correct out put But when ever I tried to change the hour to Zero $testTime = strtotime("2016-03-03 00:30:45 am"); echo "final=".$final = DATE("Y-m-d H:i",$testTime);//1970-01-01 01:00 Incorrect values are showing. Any idea? 回答1: you are using am/pm with 24 hours format. am/pm should be with 12 hr 12 hour = 12:30:45 AM $testTime = strtotime("2016-03-03 12:30:45 am"

Get date of this week thursday OR next week thursday in php

一世执手 提交于 2019-12-11 19:07:55
问题 I need to get the DATE of this week's Thursday (or any other day) OR next week's Thursday (or any other day) The scenario is that there are 3 tours happening every week.. I need to find out next tour date If today is tuesday and date is 21/01/2014 and tours happen on tuesday, friday and sunday.. then I need to find out next tour date which will be on friday on friday Similarly, if today is Friday, I'll need to find out date on next week's tuesday. So far, I tried using strtotime("next tuesday

Add one hour from _GET

China☆狼群 提交于 2019-12-11 18:14:38
问题 I'm using date('H', strtotime($_GET['h'].' +1 hour')) at the moment ( $_GET['h'] contains the hour I'm getting from the URL, i.e. 20 as in 20:00) but it only prints 01 when it should print 21 . I want to get this hour and add one hour to it so 20 will be 21 and so on. What am I doing wrong here? 回答1: Something like this should work: $time = DateTime::createFromFormat('H:i', '20:00'); $time->modify('+1 hour'); echo $time->format('H:i'); See it in action 回答2: You can add seconds to the

compare two times in php [duplicate]

删除回忆录丶 提交于 2019-12-11 17:51:34
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to compare two time in PHP Hi I am new in time functions in php, i have, @$download_time = date('d-m-Y H:i:s', $dec_time); $current_time = date('d-m-Y H:i:s'); $diff = abs(strtotime($current_time) - strtotime($download_time)); $time=65 // $time is in seconds Now I want to compare if ($diff < $time) how can I compare with this two values. 回答1: If $dec_time is a unix timestamp , then simply: if (time() - $dec

String to date conversion in PHP

空扰寡人 提交于 2019-12-11 17:25:42
问题 I'd like to convert such a date '2012 30 March 9:30 pm' into this format 2012-03-30 09:30:00 What is the easiest way to do that? I need it to be working on PHP 5.2 and older, so this solution isn't of any use for me date_format('Y-m-d H:M:S',date_create_from_format('Y m F g:i A', '2012 30 March 9:30 pm')) 回答1: This will extract each component from the date and rearrange it so that strtotime() understands. Convert to any date format you want after that. Using regex is probably overkill though.

PHP Convert from strtotime into time

我们两清 提交于 2019-12-11 11:03:22
问题 I need to add multiple time values as in Hours:mins, so I use strtotime($value1) + strtotime($value2) to add all of them, how do I put them back as hours:mins ? cant use date("h:i") it only works if hours < 24. I appreciate your help. Thanks 回答1: The function strtotime() returns the time in seconds since January 1 1970 00:00:00 UTC. So adding the return value of this function might not do what you would expect. Instead of using the date functions we can manipulate the string and perform some

why strotime returns negative value in php?

送分小仙女□ 提交于 2019-12-11 10:50:36
问题 I am using strtotime to convert a date to a unixtime stamp. Year, date and day comes as different values to code and I am using the below code to produce the timestamp. $year = '1961'; $month = '2'; $day = '15'; $date = $year."-".$month."-".$day; echo strtotime($date); The above code prints : -27648000 for me. If the year is above 1970 it prints out positive results. I am still learning with the timestamp, if any one can help me out. The main aim is to convert a date to unix timestamp. The