Jump to content


converting day of the week to numerical

  • Please log in to reply
3 replies to this topic

#1 digitalgod

  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 11 October 2006 - 08:47 PM

Hey guys,

how can I convert a day into a numerical value?

like monday --> 1  tuesday --> 2 etc

#2 obsidian

  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 11 October 2006 - 08:57 PM

echo date('w');

so, as with any other date call, pass in a timestamp of the date you want the day of the week for as a second parameter, and you're good to go.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 digitalgod

  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 11 October 2006 - 09:09 PM

that I know already, I guess I wasn't clear before :P

What I meant to say is that I have a dropdown, the value of the dropdown is a date in this format Y-m-d and what's displayed in the dropdown is something like date("l (M jS)") now when a user selects a date it calls a javascript function which extracts the day like so

var text = main_select.options[main_select.selectedIndex].text.split(" ");
var day = text[0].toLowerCase();

now I know that by using a switch statement I can change that string to a numerical value but I was wondering if there was a more efficient way of doing it.

#4 fenway

  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 11 October 2006 - 11:02 PM

Well, the Date() constuctor can take the full six-parameter version, so once you have a proper JavaScript Date object, you should be fine.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users