Jump to content

another date question *SOLVED*


digitalgod

Recommended Posts

hey guys,

I was wondering how can I take a day (such as Friday) and transform it into something like this 0000-00-00 (year-month-day)

I have a drop down that's being populated with an array like so

[code=php:0]
list($y,$m,$d) = explode("-",date("Y-m-d"));
$daysValue = array();
for ($i=0;$i<=6;$i++) {
array_push($daysValue,date("l", mktime(0,0,0,$m,$d+$i,$y)));
}

echo '<select name="night" onchange="Fill_Sub()" style="width:150px; height:17px; font-family:tahoma; font-size:10px; color:#9A400C "><option value="">Select one</option>';
for($i=0;$i<count($days);$i++) {
echo  '<option value='.strtolower($daysValue[$i]).'>'.$daysValue[$i].'</option>';
}
echo "</select>";
[/code]

so when the form is submitted I'd like to take that day and transform it into a full date (0000-00-00). I'd normally give it that value in the drop down but I can't do that here because I need the value to be something like Friday.

is there a way I can take just take that day and transform it? All the days start from today till the week after like Wednesday to Tuesday.
Link to comment
https://forums.phpfreaks.com/topic/17780-another-date-question-solved/
Share on other sites

Just put the date you're wanting into the value of the select option:

[code]<?php

list($y,$m,$d) = explode("-",date("Y-m-d"));
$daysValue = array();

for ($i=0;$i<=6;$i++) {
$n = mktime(0,0,0,$m,$d+$i,$y);
$daysValue[date("Y-m-d", $n)] = date("l", $n);
}

echo '
<select name="night" onchange="Fill_Sub()" style="width:150px; height:17px; font-family:tahoma; font-size:10px; color:#9A400C ">
<option value="">Select one</option>';

foreach ($daysValue as $key => $value) {
echo  '
<option value=' . $key . '>' . $value . '</option>';
}
echo "</select>";
?>[/code]
rather than using the value property for the select box, use the text property, which will return the string displayed, rather than the value of the option selected for your javascript function.  However, when the script is posted, it should still return the proper value...unless you change it via javascript
Use the javascript function split to seperate your day display into seperate items...

[code]var text = selectedoption.split(" ");
var day = text[0];[/code]

Something similar to that should work.

JS is not that different from PHP, the functions are just a little different, so you can do nearly all the same string manipulations.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.