PHP - Rearrange Input Date From Dd.mm.yyyy To Yyyy.mm.dd
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? Similar TutorialsHello 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> 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 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)... Hi 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, 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>"; 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 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. Hi, In my database, date is stored as in the format of YYYY-MM-DD Something like $date = 2012-04-01 How can I extract this as follows ... $year = 2012 $month = 04 $day = 01 Thanks How can I get the day of the week from DD/MM/YYYY?? Thanks! I have a calendar select date function for my form that returns the date in the calendar format for USA: 02/16/2012. I need to have this appear as is for the form and in the db for the 'record_date' column, but I need to format this date in mysql DATE format (2012-02-16) and submit it at the same time with another column name 'new_date' in the database in a hidden input field. Is there a way to do this possibly with a temporary table or something? Any ideas would be welcome. Doug Hey guys, I have a bunch of categories and products in a tree format. For several reasons I need to restructure them from the tree format into a flattened format. I have 2 arrays, one full of categories, the other products. Each category and product has an ID, and a reference to it's parent's ID. The top level categories reference to 0. What I need is to have the categories output like thus: Top Level Categories: Category 1 Category 2 Category 1 Sub category 1 Sub category 2 Category 2 Sub category 3 Sub category 4 Sub category 1 Product 1 Product 2 Sub category 2 Product 3 Product 4 Sub category 3 Product 5 Product 6 Sub category 4 Product 7 Product 8 There could be an unlimited number of sub categories within categories before we get to products, so this needs to be done through a function, however I cannot for the life of me think how to do this. Initially I thought about using 2 arrays, a buffer of categories outputted, and a queue of categories to be outputted, but quickly realised that when I go more than 2 layers deep I can't keep track of the queue's properly. Hi, I'm using the form data type 'date', and trying to verify it. It seems a little too complicated to check that it's in the correct format (with "/" between day/month/year), unless I use regular expression, which I don't know much about and seems feels like there's an alternate solution or it's not necessary. Currently, the script accepts DD*MM*YYYY, where * is any character, since it just strips the 3rd and 6th character and checks the day/month/year using checkdate(). I'm not even sure if this is a problem. I am giving the user a "verify" page, where I could put it in the correct format (DD/MM/YYYY), but is that enough? Feel like I'm missing something here, so any feedback would be great Hey guys, I've got a problem. Can anybody show me how to do it? Let's say there are 4 input fields: Year, month, day and hour. The user fills them like 2010, 12, 2, 3; and then I need a function to convert that date to datestamp with GMT +1. I was googling a whole afternoon, however came up with nothing. Thanks in advance! Hi. I have an input field where a date is entered, format dd-mm-yy. I need to query the database to see if this date exists. How can I convert the date to yyyymmdd before the query? Thanks 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. Alright, I have a Datetime field in my database which I'm trying to store information in. Here is my code to get my Datetime, however it's returning to me the wrong date. It's returning: 1969-12-31 19:00:00 $mysqldate = date( 'Y-m-d H:i:s', $phpdate ); $phpdate = strtotime( $mysqldate ); echo $mysqldate; Is there something wrong with it? 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 have a job listing website which displays the closing date of applications using: $expired_date (This displays a date such as 31st December 2019) I am trying to show a countdown/number of days left until the closing date. I have put this together, but I can't get it to show the number of days. <?php $expired_date = get_post_meta( $post->ID, '_job_expires', true ); $hide_expiration = get_post_meta( $post->ID, '_hide_expiration', true ); if(empty($hide_expiration )) { if(!empty($expired_date)) { ?> <span><?php echo date_i18n( get_option( 'date_format' ), strtotime( get_post_meta( $post->ID, '_job_expires', true ) ) ) ?></span> <?php $datetime1 = new DateTime($expired_date); $datetime2 = date('d'); $interval = $datetime1->diff($datetime2); echo $interval->d; ?> <?php } } ?> Can anyone help me with what I have wrong? Many thanks (continuing from topic title) So if I set a date of July 7 2011 into my script, hard coded in, I would like the current date to be checked against the hard coded date, and return true if the current date is within a week leading up to the hard coded date. How could I go about doing this easily? I've been researching dates in php but I can't seem to work out the best way to achieve what I'm after. Cheers Denno |