geo3d Posted April 6, 2010 Share Posted April 6, 2010 Hi folks, Looking for some help regarding syntax to place month name text to one field based on a date field. Was thinking an elseif statement would work here (i'm always open to better suggestions); note: I can't use monthname(current_date) because my date field is a date of report field that a user may input the date of report for a report last name etc; problem with the use of the wildcard? <?php $d=('DATE'); if($d =='01/%') echo "January"; elseif($d=='02/%') echo "February"; elseif($d=='03/%') echo "March"; elseif($d=='04/%') echo "March"; elseif($d=='05/%') echo "May"; ?> Quote Link to comment Share on other sites More sharing options...
tomtimms Posted April 6, 2010 Share Posted April 6, 2010 A bit confused, however I assume your using a form and the field is DATE. You may want to make $d=('DATE'); = $d=$_POST('DATE'); assuming your using the POST method. Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 6, 2010 Share Posted April 6, 2010 No need for IF statements at all: $d = '02/%'; echo date('F', mktime(0,0,0, preg_replace("/[^\d]/", '', $d))); //Output: February Quote Link to comment Share on other sites More sharing options...
geo3d Posted April 7, 2010 Author Share Posted April 7, 2010 Sorry for the confusion and thanks for the replies; To be more clear; I have a calendar input item that a user clicks and gives me a date (the field is called DATE OF REPORT); the result example is 03/21/10. I have a hidden field (called Month - which feeds a chart program). The Month field result needs to be in Cleartext; example March. So my question is how can I pull the first 2 characters from DATE OF REPORT result and post to MONTH field in cleartext? Again, I can't use monthname(current_date) because users might be inputting DATE OF REPORT from a previous month(s). I hope this more clear and thanks again for the replies. I've attached a screenshot of my form. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
tomtimms Posted April 7, 2010 Share Posted April 7, 2010 Not sure you would actually need a hidden field, if you are inserting this into your database as the Month field you can just take the Date Of Report field and explode its values. So in your php file where you are inserting your form data I would do this. if (isset($_GET['Date Of Report'])) { $date = $_GET['Date Of Report']; } else { $date = ''; } Then I would explode $Date. $report_date = date("m/d/Y", strtotime($date)); $dateXplode = explode("/", $report_date); $report_month = $dateXplode[0]; $report_day = $dateXplode[1]; $report_year = $dateXplode[2]; now lets conver the month number to month name. $report_month = date("F", mktime(0, 0, 0, $report_month, 10)); Now you have each date value MONTH/DATE/YEAR as there own values. You can now insert into $start_month into your query as Month=$report_month. I hope this helps. This is all untested however should give you a great starting point. Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 7, 2010 Share Posted April 7, 2010 This is ALL you need. $monthName = date('F', strtotime($_POST['DATE OF REPORT'])); If the input ($_POST['DATE OF REPORT']) = "03/21/10", then $monthName will be "March". Will work for any valid date. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.