Hi I have string variable containing date from which I would like to extract only the day.
Date format: dd/mm/yyyy
Hi I have string variable containing date from which I would like to extract only the day.
Date format: dd/mm/yyyy
DateTime date_var= new DateTime(2017, 10, 13);
Console.WriteLine(date_var.Day);
even
datetime.ToString("dd")
will also work
Regards…!!
Aksh
try this -
Date.ParseExact(string,“dd/mm/yyyy”,System.Globalization.DateTimeFormatInfo.InvariantInfo).ToString(“dd”)
or
Left(string,2)
Hi Dominic,
Found this one as a solution to one of my problems, Just curious to know what is it(("/"c)(0) called?
Thanks
Kiran
Hi @kiranmili,
Split the string based on “/” so you can get the value.
For example “01/02/2018” is your string, so you are going to split using “/”
yourstring.Split("/"c")
so you can get the array value like 01,02,2018 totally 3 values
yourstring.Split("/"c")(0)
-.> so you will get the first value of the array.
Refer this link
https://www.dotnetperls.com/split
Regards, Arivu
Thanks Arivu,
I understood the split string and how it works but what is the “c” inside the split function. c as in character? or what it refers to .
It will be really helpful if you can provide input on this, as i have another scenario with a string with Unicode characters.So understanding this will be useful to direct me what i can use for unicode chracters.
Thanks again,
kiran
Hi @kiranmili,
You can try like the below statement, where you need to pass a string instead of the date value in it.
DateTime.ParseExact(Convert.ToDateTime(“06/19/2018”).Date.ToString(“MM/dd/yyyy”), “MM/dd/yyyy”, Nothing).ToString(“dd”)