Jump to content

Archived

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

digitalgod

another date question *SOLVED*

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.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
well that's what I said.... I'd normally do that but I can't, I need the value to be a day because when the user selects a day javascript/php checks to see if that day has subcategories and if it does it populates the 2nd drop down.

is there another way?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
darn it I forgot that the text is different from the value... the drop down looks like

Wednesday (Aug 16th)  and the value looks like wednesday... I added that so that people don't get confused

hmm any other suggestions?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.