0
$\begingroup$

I asked this earlier, but removed my post because I was able to create some more code for it. I am writing a program that asks a user for their birthdate in three separate steps, month, day and year, where the month is given as a word, like "March". I want this program to return the date in the form "mm/dd/yyyy". So a day such as 9 would be written as 09, and I specified that to the user in the Input window..I don't know how to put all this together,to actually get an output of "mm/dd/yyyy".

Clear[month, day, year, monthSwitch, blah];
 month = Input["What is your birthday month? Such as " April ""];
 day = Input["What day is your birthday? If the day number falls in between 1-9, please enter 0 number, such as 09 "];
 year = Input["What year were you born in? Please enter the 4 digit year, such as 1994"]

 blah[monthSwitch_] := 
Switch[monthSwitch, "January", "01", "February", "02", "March", 
"03", "April", "04", "May", "05", "June", "06", "July", "07", 
"August", "08", "September", "09", "October", "10", "November", 
"11", "December", "12", _, monthSwitch];

I feel like I need nest some of these inputs into an If statement or something, but not too sure.

$\endgroup$
1
$\begingroup$
birth := Module[{blah, month, day, year},

  blah[monthSwitch_] := 
   Switch[monthSwitch, "January", "01", "February", "02", "March", 
    "03", "April", "04", "May", "05", "June", "06", "July", "07", 
    "August", "08", "September", "09", "October", "10", "November", 
    "11", "December", "12", _, monthSwitch];
  month = blah @ ToString @ Input["What is your birthday month? Such as " April ""];

  day = StringPadLeft[ToString @ Input["What day is your birthday?"], 2,  "0"];

  year = ToString @ Input["What year were you born in? Please enter the 4 digit year, such as 1994"];

  month <> "/" <> day <> "/" <> year

  ]

Usage: just type birth in a new cell.

Note that birth is a function, so it will not store the date by itself. By typing, e.g.,

date = birth

the date will be assigned to date and you can access it without calling birth again.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.