PHP - Can I Convert A Yyyy-mm-dd To Full Date?
hello, i have the following code and it is ok. what im trying to do is convert a 2010-09-20 post from a form and have it read out as Monday September 20, 2010.
is this possible? Code: [Select] $dateselected="$_POST[Y]-$_POST[M]-$_POST[D]"; echo "<table border='1'>"; echo "<tr><td width='100%' colspan='4' align='center'>$_POST[M]-$_POST[D]-$_POST[Y]</td></tr>"; Similar TutorialsHi I need to change a uk date dd/mm/yyyy to mysql format yyyy/mm/dd I have a user form where they enter the date in dd/mm/yyyy string format, i want to take that string, and convert it to mysql format yyyy/mm/dd Possible? Ive searched for ages and havent found a solution that works. Is there an easy solution to this? surely there must be Cheers How can I convert a database time to mm/dd/yyyy from yyyy-mm-dd when pulling from database to display, and vice versa when from form to database? Hello Everyone I am working on a website for my favorite hobby. I have created the dynamic pages and they are ready to go. I am having trouble however with the dates. I want all the dates to show up as MM-DD-YYYY. Not sure how to do that with a while loop. I am also trying to figure out how to make the date say "Lost Info" if the date is showing the default.(0000-00-00) Here is my code so far Code: [Select] <?php include('../../includes/config.php'); $sql = 'SELECT id, l_name, f_name, date_sent, date_return, item_return FROM `ttmautos` WHERE `l_name` LIKE \'a%\' AND `category` LIKE \'baseball\' ORDER BY `date_return` DESC'; $link_result = mysql_query($sql, $connection) or die(mysql_error()); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" type="text/css" href="../../css/reset.css"/> <link rel="stylesheet" type="text/css" href="../../css/top_nav.css"> <link rel="stylesheet" type="text/css" href="../../css/main_layout.css"/> <script src="../../scripts/jquery-1.4.4.js" type="text/javascript"></script> <script src="../../scripts/top_nav.js" type="text/javascript"></script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Baseball Autographs A</title> </head> <body> <div id="wrapper"> <?php include('../../includes/page/header.php'); ?> <?php include('../../includes/page/top_nav.php'); ?> <?php include('../../includes/page/left_sidebar_autopages.php'); ?> <?php include('../../includes/page/right_sidebar.php'); ?> <div id="content"> <ul class="list_heading"> <li class="title">player name</li> <li>date sent</li> <li>date recievied</li> <li class="return">item recievied</li> </ul> <ul class="list"> <?php while ($link=mysql_fetch_array($link_result)){ echo "<li>$link[f_name] $link[l_name]</li> <li>$link[date_sent]</li> <li>$link[date_return]</li> <li class=\"return\"><a href=\"/auto_pages/baseball/baseball-autographs.php?l_name=$link[l_name]&f_name=$link[f_name]\">$link[item_return]</a></li>"; } if($link[date_sent]=="0000-00-00") { echo "Lost Info"; } if (!($link = mysql_fetch_array($link_result))) { return "Currently our database has no autographs listed for here"; } ?> </ul> </div> <!--END content div--> </div> <!--END wrapper div--> <?php include('../../includes/page/footer.php'); ?> </body> </html> yeah... in norway, we use dd.mm.yyyy, but mysql date uses yyyy.mm.dd.. Is there any php lines i can use to rearrange the input dates? And also, rearrange the date when i query the mysql for the dates? Hello everyone, I am not sure if I am googling this wrong or what. I have several dates in a mysql database that I would like to display in a dynamically made page. Can someone help me or point me in the right direction. I am very unfamiliar with the MySql date function. I would also like to calculate the days that have passed between two different dates. Example would be: 11-27-2011 and 12-15-2011 = # of days Hey, I'm using a script which allows you to click on a calendar to select the date to submit to the database. The date is submitted like this: 2014-02-08 Is there a really simple way to prevent rows showing if the date is in the past? Something like this: if($currentdate < 2014-02-08 || $currentdate == 2014-02-08) { } Thanks very much, Jack Hello. I'm new to pHp and I would like to know how to get my $date_posted to read as March 12, 2012, instead of 2012-12-03. Here is the code: Code: [Select] <?php $sql = " SELECT id, title, date_posted, summary FROM blog_posts ORDER BY date_posted ASC LIMIT 10 "; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)) { $id = $row['id']; $title = $row['title']; $date_posted = $row['date_posted']; $summary = $row['summary']; echo "<h3>$title</h3>\n"; echo "<p>$date_posted</p>\n"; echo "<p>$summary</p>\n"; echo "<p><a href=\"post.php?id=$id\" title=\"Read More\">Read More...</a></p>\n"; } ?> I have tried the date() function but it always updates with the current time & date so I'm a little confused on how I get this to work. I have set up a function to validate user input date in yyyy-mm-dd format taking into account the following possibilities:
the length of the month
February 29th when the year is not a leap year
When I run the code, I do not get any feedback whatsoever, when it should.
This is the code below and I would appreciate your thoughts:
if(!function_exists('checkdate')) { function checkdate($date, $checkyear, $currentmonth) { if($checkyear == 0)//if it is not a leap year { // if current month is february if($currentmonth == 2) { if(!preg_match("/^(20)\d\d[-](0[1-9]|1[012])[-](0[1-9]|1[0-9]|2[0-8])$/", $date)) { // set error for date field return ($error = 'Invalid Date!'); } return ($error = 'valid Date!'); } // if current months are april, june, september or november elseif($currentmonth == 4 || $currentmonth == 6 || $currentmonth == 9 || $currentmonth ==11) { if(!preg_match("/^(20)\d\d[-](0[1-9]|1[012])[-](0[1-9]|1[0-9]|2[0-8]|3[0])$/", $date)) { // set error for date field return ($error = 'Invalid Date!'); } return ($error = 'valid Date!'); } else { if(!preg_match("/^(20)\d\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-8]|3[01])$/", $date)) { // set error for date field return ($error = 'Invalid Date!'); } return ($error = 'valid Date!'); } } elseif($checkyear == 1)//if it is a leap year { // if current month is february if($currentmonth == 2) { if(!preg_match("/^(20)\d\d[-](0[1-9]|1[012])[-](0[1-9]|1[0-9]|2[0-9])$/", $date)) { // set error for date field return ($error = 'Invalid Date!'); } return ($error = 'valid Date!'); } // if current months are april, june, september or november elseif($currentmonth == 4 || $currentmonth == 6 || $currentmonth == 9 || $currentmonth ==11) { if(!preg_match("/^(20)\d\d[-](0[1-9]|1[012])[-](0[1-9]|1[0-9]|2[0-9]|3[0])$/", $date)) { // set error for date field return ($error = 'Invalid Date!'); } return ($error = 'valid Date!'); } else { if(!preg_match("/^(20)\d\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/", $date)) { // set error for date field return ($error = 'Invalid Date!'); } return ($error = 'valid Date!'); } } } $todate = getdate(); $currentmonth = $todate['mon']; $checkyear = date('L'); $date = 2014-02-31; echo checkdate($date, $checkyear, $currentmonth); Edited by terungwa, 26 July 2014 - 02:43 PM. guys, im having a problem here... i tried too many ways to convert dates in american format, to brazilian format, but no one is working... how can i do that, to convert it to dd/mm/yyyy (it comes from my db in mysql)... I'm trying to do this with the code below. I get an error because explode thinks I'm just sending it one argument since the string is held by an array element. If I can get the array from the explode function I can insure it into the first and last name fields in my table. Any suggestions? --Kenoli require '__classes/Db.php'; $sql = "SELECT name FROM tbl_persons"; $stmt = $pdo->query($sql); $row = $stmt->fetchall(PDO::FETCH_ASSOC); foreach ($row as $name) { $names = explode($name['name']); }
I have tried a large number of "solutions" to this but everytime I use them I see 0000-00-00 in my date field instead of the date even though I echoed and can see that the date looks correct. Here's where I'm at: I have a drop down for the month (1-12) and date fields (1-31) as well as a text input field for the year. Using the POST array, I have combined them into the xxxx-xx-xx format that I am using in my field as a date field in mysql. <code> $date_value =$_POST['year'].'-'.$_POST['month'].'-'.$_POST['day']; echo $date_value; </code> This outputs 2012-5-7 in my test echo but 0000-00-00 in the database. I have tried unsuccessfully to use in a numberof suggested versions of: strtotime() mktime Any help would be extremely appreciated. I am aware that I need to validate this data and insure that it is a valid date. That I'm okay with. I would like some help on getting it into the database. Hi, I am trying to convert a String date into numeric date using PHP function's, but haven't found such function. Had a look at date(), strtotime(), getdate(); e.g. Apr 1 2011 -> 04-01-2011 Could someone please shed some light on this? Regards, Abhishek Hi all, I have a database with some timestamps (in seconds) in it. Now I want to reverse it to normal readable time and date formats. Will someone tell me how please. Thnx Ryflex Hi In sql we have dates like this 134238 In php it shows - 19:10:11 . we can make it by using date('d.m.y', $date); where $date=134238 ; my question is how can we turn 19:10:11 in to 134238 using PHP Hi all, I'm having a bit of trouble a script running on a site where it converts a date of birth in a database shown like this '30/04/1993' to an actual age, for instance 18 in this case. Only the script I'm using below shows this age as 17, not 18 as it should be. Code: [Select] <?php $birthday = $row_getdets['dob']; function birthday ($birthday){ list($day,$month,$year) = explode("/",$birthday); $day_diff = date("d") - $day; $month_diff = date("m") - $month; $year_diff = date("Y") - $year; if ($day_diff < 0 || $month_diff < 0) $year_diff--; return $year_diff; } ?> So i've tried to remedy this myself with the following: Code: [Select] <?php $birthday = $row_getdets['dob']; function birthday ($birthday){ list($year,$month,$day) = explode("/",$birthday); $year_diff = date("Y") - $year; $month_diff = date("m") - $month; $day_diff = date("d") - $day; if ($month_diff < 0) $year_diff--; else if (($month_diff==0) && ($day_diff < 0)) $year_diff--; return $year_diff; } ?> ..but I'm having a syntax error (unexpected T_LINE), most probably down to my novice ability, I bet I've missed something simple. I'm still learning guys and I'd really appreciate any help at all. while I'm reading the cell value '20/09/1980' from an excel file using phpexcel class method $student[$i]['d_o_b'] = $objWorksheet->getCell('G' . $intRow)->getValue(); getting the value as '29484' pls help me to convert it into the date format again. Is it possible to convert time(); to date();? sorry, I know this is simple, but stuck on it... how would one go about converting 1/21/11 to a UNIX timestamp, something like 1293035229? and while we are at it, how to convert 1293035229 to 1/21/11 ? (i know the timestamp is wrong, just for example) thanks!!!!! 2011-02-05T18:07:57.00+0000 This is a string. Hello, i need a fast convertor that converts the date format 03-03-2008, 08:26 PM into a timestamp fast. Like, you paste 03-03-2008, 08:26 PM into a post form, submit and it gives you the time stamp. I made a convertor a whille ago, but you need to insert each numbers into a separate input box (day, months, year etc) I cant remember how exactly it functions etc asi haventtouched PHP In a while..... |