help datetime
i want to make a program were i type in my social security number and it says which day i was born in example user writes 2000, 04, 28, computer says you are born on a Friday
44 Replies
so uh, since I'm not in the US, just to make it clear, the social security number is ID in format of NNN-NN-NNNN and doesn't actually contain any information related to the date of birth, right?
ups
i mean
the number you are born
in so
so you meant date of birth
YYYY - MM - DD
right
yeah
m
b
hahahaha
static void inmatning()
{
var birthDate = new DateTime(2000, 04, 28);
var thisYear = new DateTime(DateTime.Today.Year, birthDate.Month, birthDate.Day);
var dayOfWeek = thisYear.DayOfWeek;
Console.WriteLine(dayOfWeek);
}
made this so far
so there's a built-in type called
DateTime
you can usebut it says thursday
oh yeah you figured it out it seems
hmmmmm
but it was a friday
when i googled it
so what you want is
you want to know which day of week it was on 2000/04/28?
yeah
and later i want to translate that into what the user inputs
birthDate.DayOfWeek
is the correct one then, I'm not sure what you're doing with thisYear
thing exactly
because from what I see thisYear
is 2022-04-28yeah i can basically remove that
OH
so
dayOfWeek
which is thisYear.DayOfWeek
would give the day of week your birthday would be this yearI FIGURED IT OUT
thxxxx
good
hahahaha
now i just need to make it so the userinputs it
with -
is that possible
you have two ways of going about it I see
one is to read three integers, separately
can i make it all in one row ?
and is it possible to use arrays here
?
basically ask "year of birth" "month of birth" "day of birth" then create a
DateTime
from it
alternatively, take in a string in some fixed format, like yyyy-MM-dd
(where yyyy, MM, dd are the actual numbers)yeah
and use
DateTime.Parse
(or ParseExact
) to create a DateTime
object directly from the string itself
it'll do the parsing for you
however it has to be in that exact format
anything other than that, like a random whitespace or comma in random places, will result in error
not sure where you could use an array there
I mean, sure, you could if you try
like taking in a string like 2022-03-04
, calling Split
to make it a string array
but why so if you could just use DateTime.Parse
/ParseExact
how will the code look like
now you have three strings (which should be numbers) in the
numbers
array
which you need to now turn into integer (I hope you know how to do that) and feed it into DateTime
's constructor
alternatively, using ParseExact
:
though use TryParseExact
yeah, that is also a valid suggestion
ParseExact will just fail with an error if it receives an invalid input
TryParseExact
will tell you whether it failed or not instead, giving you opportunity to retrydont know how to do that :S
just tried a bit
hint:
int.Parse
should i create new ints
3 new ints ?
int.Parse(input);
this ?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Console.WriteLine("Enter your date of birth in year - month - date order, separated by a single whitespace");
string input = Console.ReadLine();
string[] numbers = input.Split();
int.Parse(input);
var birthDate = new DateTime(input[0], input[1], input[2]);
var dayOfWeek = birthDate.DayOfWeek;
Console.WriteLine(dayOfWeek);
tried this
and didnt work
lmao
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
so int s = int.Parse(input);
and should input be in the "()"
dont know :S
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
"input" may be null here
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
the numbers[]
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
int s = int.Parse(numbers[]);
tried this
but it turns red
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
hmm
cant seem to figure it out :/
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I FIGURED IT OUT
THANKS
hahahahahahha