PHP - Mktime()
My friend a I have to different numbers when we echo mktime(0,0,0,5,12,1990).
How is this possible? I thought that only, we you leave some parameters blank, the local this is used, else, it's standardized. thanks in advance Similar Tutorialshow do I use strtotime() instead of mktime()? $matchTimea = mktime($mHour, $mMinute, 0, $mMonth, $mDay, $mYear); if($matchTimea-time() < $cutoffTimea*60) { New user of PHP here! I'm using it to display entries from my MYSQL database. Image below. This is the code snippet that displays information from the 'name', 'author' and 'date' columns of my database. I learned this technique from w3schools. $result = mysql_query("SELECT * FROM levels ORDER BY date DESC"); while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['author'] . "</td>"; echo "<td align='right'>" . $row['date'] . "</td>"; echo "</tr>"; } I would like to use the date() function to format the date differently. But the date() function requires that I convert my time into a timestamp. I know you have to use the mktime() function for this, but I don't know how. Can someone show me how to pass the contents from $row[date] into the mktime() function? I'm practising how to do date and time in PHP. I wanted to see if I can get all of the date/time variables from user submission and format them correctly. I went with ISO 8601 date... // From the Manual: // date('c', mktime(1, 2, 3, 4, 5, 2006)); // Prints something like: 2006-04-05T01:02:03+00:00 ...but my attempts always produce a slightly different result for the year, month and timezone... Code: [Select] $inputTime = date('c', mktime((int)$timeHour, (int)$timeMins, (int)$timezone, (int)$dateMonth, (int)$dateDay, (int)$dateYear)); echo $inputTime; // Should return: 2013-11-02T02:30:01+00:00 // Instead returns: 2012-12-02T02:30:01-08:00 The timezone value coming from HTML... <option value="1.0">(GMT +1:00)</option> I noticed; 1. It always picks a year less than whatever year I select. 2. It always selects 12 as the month. 3. It always adds -08:00 after the picking the correct timezone. How come? Thanks in advance. I'm an extreme newbie and have this current error on my site. The error states: Warning: mktime() expects parameter 4 to be long, string given in featured_product.php on line 75 <?php for ($i = 0; $i < $num_rows; $i++) { $id = mysql_result($result,$i,"id"); $title = mysql_result($result,$i,"title"); $featured = mysql_result($result,$i,"featured"); $feature_date = mysql_result($result,$i,"feature_date"); $feature_date_arr = explode("-",$feature_date); $feat_date = mktime(0,0,0,$feature_date_arr[0],$feature_date_arr[1],2000+$feature_date_arr[2]); if ( ($feat_date+($featured*24*60*60))<time() ) { $db2->query("UPDATE product_catalog SET featured = 0 WHERE id='$id'"); $featured = 0; } else { $featured = 1; $db2->query("UPDATE product_catalog SET featured = 1 WHERE id='$id'"); } ?> Any ideas on how to correct this? Thanks! right now i have my date system to say "X amount of seconds ago, X hours ago, X days ago, X years ago, How could i turn mktime() (1290874161) into a mm/dd/yyyy format? so it would say like, "Nov 27, 2010 at Hour:Minute" (whatever the hour/minute is) Or am I just going crazy? OK, I've been running a query that uses the snippet below to get the previous month. It's : Code: [Select] $sql = "SELECT COUNT(`id`) as `counted` FROM `click_tracking` WHERE `date` LIKE '". date('Y-m', mktime(0, 0, 0, (date('m')-1), date('d'), date('Y'))) ."-%'"; Here's a snippet for people to try: Code: [Select] date_default_timezone_set('America/Toronto'); echo date('Y-m', mktime(0, 0, 0, (date('m')-1), date('d'), date('Y'))); //prints 2012-03 (March, which is incorrect; should be February- 2012-02) That should have printed 2012-02, but instead, it prints 2012-03. If I modify the mktime() to (date('m')+1): Code: [Select] date_default_timezone_set('America/Toronto'); echo date('Y-m', mktime(0, 0, 0, (date('m')+1), date('d'), date('Y'))); //prints 2012-05 (May, which is incorrect; should be April - 2012-04) It prints 2012-05 which is incorrect for the given timezone. Should be 2012-04 I'm thinking it's a leap year bug and will work itself out tomorrow (per my timezone, anyways). So, when I use the mktime() function, it seems to be thinking we're in April already. A standard date('Y-m') prints the correct YYYY-MM (2012-03) though. Am I tripping out? Hi, I'm getting this error: Warning: mktime() expects parameter 5 to be long, string given in /home/user/public_html/include/functions.php on line 58 The code is: if($Date_Format == 1) #For dd-mm-yyyy { $Date_Output = date("d-m-Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 2) #For dd/mm/yyyy { $Date_Output = date("d/m/Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 3) #For mm-dd-yyyy { $Date_Output = date("m-d-Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 4) #For mm/dd/yyyy { $Date_Output = date("m/d/Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 5) #For Mon Day YYYY { $Date_Output = date("M D Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 6) #For Month Day YYYY { $Date_Output = date("F D Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 7) #For Date"nd" Month YYYY { $Date_Output = date("d\\t\h F Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 8) #For Month Day YYYY { $Date_Output = date("F d Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 9) #For Month Day YYYY { $Date_Output = date("d/m/Y H:i",mktime($DateDispsplittimehr,$DateDispsplittimemin,0,$Month,$Day,$Year)); // Line 58 } return $Date_Output; } else { return NULL; Line 58 says $Date_Output = date("d/m/Y H:i",mktime($DateDispsplittimehr,$DateDispsplittimemin,0,$Month,$Day,$Year)); I really appreciate any help on this. I want to have a couple of different formats from mktime(), which the value could be: 1292183335. I would like to have some of the formats like: Tuesday at 12:00am, Wednesday, January 12, 2011 at 12:00am Also taking different timezones in consideration. I'm not sure what to use for that. |