Jump to content


Photo

another date question *SOLVED*


  • Please log in to reply
7 replies to this topic

#1 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 16 August 2006 - 10:16 PM

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

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

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.

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 17 August 2006 - 12:15 AM

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

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


#3 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 17 August 2006 - 12:40 AM

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?

#4 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 17 August 2006 - 12:46 AM

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

#5 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 17 August 2006 - 12:56 AM

ahhh never thought of that, I'll give it a shot and post back

#6 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 17 August 2006 - 01:11 AM

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?

#7 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 17 August 2006 - 01:21 AM

Use the javascript function split to seperate your day display into seperate items...

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

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.

#8 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 17 August 2006 - 09:17 PM

thanks hitman, worked perfectly.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users