PHP - Strtotime Doesn't Like October
Similar TutorialsI want to only show Events that occur in October. I'm a little unsure how to modify this code... Code: [Select] // Build query. $q = 'SELECT name, location, dateandtime FROM topic WHERE dateandtime=?'; // Prepare statement. $stmt = mysqli_prepare($dbc, $q); // Bind variable. mysqli_stmt_bind_param($stmt, 'i', $id); Is there a PHP function that I should use? Or do I just use a conditional? And not sure if I even need a bound variable here. Debbie Hello,
I'm trying to use strtotime to add time to a mysql type timestamp. Any help would be appreciated. I think I have tunnel vision from looking at it when I know it has to be something obvious...lol
$start = "2014-05-22 09:16:24"; $type = 30; $endtime = date($start,strtotime("+ '.$type.' minutes")); echo "End: ".$endtime."</br>Start: ".$start;Right now it returns: End: 2014-05-22 09:16:24 Start: 2014-05-22 09:16:24 First time posting code and very new to php aka learning as I go... The below code works as shown, but in the 'else' clause, I'd like to replace the +4 with a variable. How to do this? I've tried, Code: [Select] $renewaldate = strtotime($subscriptiondate); $sft = "' +" . $duesmultiplier . " year'"; $next_year = date('Y-m-d',strtotime($sft,$renewaldate)); but this doesn't return what I expect. Perhaps this can't be done using this technique? Code: [Select] if($n == 0) { $renewaldate = strtotime($subscriptiondate); $next_year = date('Y-m-d',strtotime('next year',$renewaldate)); echo $next_year; } else { $renewaldate = strtotime($subscriptiondate); $next_year = date('Y-m-d',strtotime('+4 year',$renewaldate)); echo $next_year; } Thank you Hi, I have a bit of an issue with my application, I didn't notice until today, Sunday... Apparently PHP sees Sunday as the first day of the week, which I cannot fathom where it got hat notion from... but anyway, so I have the following samples of my code: Code: [Select] $mondayoflastweek = date('Y-m-d H:i:s', strtotime('monday last week')); $sundayoflastweek = date('Y-m-d 23:59:59', strtotime('sunday last week')); The crazy and very troublesome thing about the results of that code is that if you run that today, Sunday, it shows today as last week... So therefore, the next bit of code is just as problematic: Code: [Select] $mondayofthisweek = date('Y-m-d H:i:s', strtotime('monday this week')); $sundayofthisweek = date('Y-m-d 23:59:59', strtotime('sunday this week')); As you can imagine, for payroll, this is causing a big problem... My week starts at precisely 12:00 am on Monday and ends at precisely 11:59 pm on Sunday... Could someone please help me out with this... Hello! A user is going to input a date in the form "mm/dd/yyyy". I'd like to convert this to a time stamp so that I can store it via MySql. I've heard about the "strtotime" function in PHP but I'm not sure how it can tell that the user 03/04/2011 represents March,4th 2011 and not, say April,3rd 2011 (European version). Help with the correct syntax for conversion would be greatly appreciated. Thank you, Eric So, my problem is that I need to edit my Xmas calculator to understand when this year's Xmas is over, it will automatically jump to the next one (2011-12-25). I have no idea how to do this (noob to php...) Thanks in advance. Here's my code: Code: [Select] <?php $time=time(); $xmas=strtotime("2010-12-25 00:00:00"); $diff = $xmas - $time; $days=intval($diff/86400); $left=$diff%86400; $hs=intval($left/3600); $left=$left%3600; $mins=intval($left/60); $secs=$left%60; echo "<font size=12 face=corbel> Xmas is after:<br> <strong>$days days</strong><br> <strong>$hs hours</strong><br> <strong>$mins mins $secs secs</strong>! </font>"; ?> when i use strtotime('+3 HOURS') everything is fine. so why cant i use strtotime('+3.5 HOURS')? what would be the proper way to do this? I'm trying to add 5 days to $today date: Code: [Select] <?php $exp_date = "2011-09-11"; $todays_date = date("Y-m-d"); $today = strtotime("+5 days", $todays_date); $expiration_date = strtotime($exp_date); if ($expiration_date > $today) { echo "Valid: Yes"; } else { echo "Valid: No"; } ?> Is +5 days used wrong? I have this php code: length is 15 , that is what it is coming out of the database $length = $get['length']; $time = date('Y-m-d', strtotime('+$length days')); But when I echo time it comes out with this result 1969-12-31 What am I doing wrong? can someone please tell me how to echo the current time or date? I have the date in the format 1306768978 in the database but I dont want to echo it back that way obviously. Not only that but does anybody know of a good tutorial on how to use this function? Little confuzzled. I have got a bunch of listings that will be printed at the end of the page but I need to subtract a time specified in a textbox (send it to itself) on the page. Code: [Select] $row['active'] = (strtotime('$row[etd]') + $rwy1 = $_POST['tmatttextfield']);Well this just converts the time in the database which is always going to be a four character number such as: 1300 for 1PM into a time and adds the textbox value to the time. Code: [Select] <td width="50" bgcolor="<?php echo $bc?>"><strong><?php echo date('hi', $row['active']);?></strong></td>That just prints it all out formatting the time to only Hours and Minutes. So just to clarify the user would put in say '10' in the textbox which would constitute 10 minutes. The code above should then define that '10' as 10 minutes. Define the database result, ie. 1500 as 3PM and add the 10 minutes to it so it would become 1510. I have been getting some wierd and wonderful results whilst trying to get it to work. Mainly just 1200 though. Harry. hello, what am i doing wrong? Code: [Select] $starttime=$row['starttime']; $esttime1=date( 'g:i a', strtotime(-2 hours, $starttime) ); Hey freaks, running into a little issue with the use of date and strtotime.... basically I wanna present the date in the format m-d-y to the user and insert it into the DB in the Y-m-d format. What seems to be happening is a freaky Y-d-m format and I don't know why this is. This code is an example that expresses my frustration. Code: [Select] $nmon = strtotime("next Monday"); $next = date('m-d-Y', $nmon); $_SESSION['REPORT_DUE'] = $next; $nfri = strtotime("Friday"); $due = date('m-d-Y', $nfri); $_SESSION['WEEK_ENDING'] = $due; $ses1 = $_SESSION['WEEK_ENDING2'] = date('Y-m-d', strtotime($due)); $ses2 = $_SESSION['WEEK_ENDING3'] = date('d-m-Y', strtotime($ses1)); .....output.... Quote [WEEK_ENDING] => 09-02-2011 [WEEK_ENDING2] => 2011-02-09 [WEEK_ENDING3] => 09-02-2011 ) Thank you for any assistance. Hi I am new to PHP and trying to convert a date from a registration form (in the form 01/01/2011) to Y-m-d so that it can be stored in the database. This is the code I have, pretty sure it worked before but not it has stopped working! Any ideas? $dateformat = $_POST['dob']; $correctformat = date('Y-m-d',strtotime($dateformat)); I have checked what $_POST['dob'] is printing and that is correct, however the $correctformat is printing 1970-01-01 everytime. Any help would be greatly apreciated. Thank you Hi! the following code sucessfully outputs a timestamp. Code: [Select] $datealt=strtotime('2012-03-13 ,23:13:00'); The following however does not: Code: [Select] $datealt=strtotime('$date ,$hours:$minutes:00'); I have checked if the variables echo out and they do.. any clues much appreciated x so i have a basic html table and down the left column i have monday,tuesday,wednesday.... sunday. In the column 2nd from the left, i want to fill it with the current weeks dates, which is really based on the current date. So if today is Jul 29th Friday, then strtotime("last monday") would give me Jul 26th Monday... my issue is "last monday" wont work if today is monday because that will give me 19th of july... and since I technically dont know what day is today i'm not sure how to cleanly work around this without having to use some if statement... if today is monday do "last monday +7 days" or just do "now" etc... Thanks! Good Day, I'm struggling to get strtotime() to return anything. I have the following code.. $fields['birth']['day'] = 9; $fields['birth']['month'] = 7; $fields['birth']['year'] = 1982; $dob = $fields['birth']['day'].' '.$fields['birth']['month'].' '.$fields['birth']['year']; // Returns: 9 7 1982 $dob = strtotime($dob); die($dob); No matter what I do $dob isn't returning anything once strtotime() is used. I've tried matching my day/month/year 's with examples in the manual on the strtotime() page but using date() on the fields, but it still doesn't want to return anything. I feel I'm missing something simple here. Any help is appreciated. Regards, Ace what is the propper way to write Code: [Select] $payrollweek="10"; date('Y-m-d', strtotime("+($payrollweek - 2) week $payrollend") ), "<br />"; its the ("+($payrollweek - 2) that isnt working i think how do I use strtotime() instead of mktime()? $matchTimea = mktime($mHour, $mMinute, 0, $mMonth, $mDay, $mYear); if($matchTimea-time() < $cutoffTimea*60) { I'm having a bit of trouble converting dates from strings. "171630Z - 181200Z" is what I would like to convert. I want to be able to display more information via date() with strtotime(). The timezone I would prefer is Central. To explain what the string represents: 17 = day (December 17th - today) 1630Z = time in UTC/GMT 18 = day (December 18th - tomorrow) 1200Z = time in UTC/GMT Is there an easy way of doing this or is it impossible with just the day and time in UTC? Thanks. Edit: I would also like to convert "1009 AM CST FRI DEC 17 2010" but that isn't working either. |