Jump to content

Recommended Posts

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";


?>

Link to comment
https://forums.phpfreaks.com/topic/197794-php-elseif-statement/
Share on other sites

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]

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.