How to get date alone without time [Resolved]

Posted by Oswaldlily under C# on 8/2/2012 | Points: 10 | Views : 2844 | Status : [Member] | Replies : 6
Date=20
Month=7
Year=2012

Datetime _dt=new Datetime();
_dt=r.Date + "/" + r.Month + "/" + r.Year

this gives with time 20/07/2012 00:00:00
I no need time..so hw to eliminate?




Responses

Posted by: Ogipansrk on: 8/2/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
For converting string to date
-------------------------------------

SELECT convert(datetime, '10/23/2016', 101) -- mm/dd/yyyy
SELECT convert(datetime, '2016.10.23', 102) -- yyyy.mm.dd ANSI date with century
SELECT convert(datetime, '23/10/2016', 103) -- dd/mm/yyyy
SELECT convert(datetime, '23.10.2016', 104) -- dd.mm.yyyy
SELECT convert(datetime, '23-10-2016', 105) -- dd-mm-yyyy

But you table column should be as "Date" datatype




Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ogipansrk on: 8/2/2012 [Member] Starter | Points: 25

Up
0
Down
int Date = 20;
int Month = 7;
int Year = 2012;

DateTime _dt = new DateTime(Year, Month, Date);

DateTime _dtt = _dt.Date;
Response.Write(_dtt.ToString("d"));

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 8/2/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
 

int Date = 20;
int Month = 7;
int Year = 2012;
DateTime dt = new DateTime(Year, Month, Date);
DateTime dt1 = dt.Date;
Response.Write(dt1.ToString("dd/MM/yyyy"));

Output : 20/07/2012 (dd/mm/yyyy)





Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oswaldlily on: 8/2/2012 [Member] Starter | Points: 25

Up
0
Down
@Ranjeet_8

Ok according to yu I changed to string..
Now when I pass into store Procedure I m passing as string.
But inside storeProcedure code I need to change to Datetime which also should contain oly date without time.How to do that?


Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 8/2/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
@Oswaldlily

follow the above code for converting string to date inside the stored proc.

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Saranpselvam on: 4/4/2014 [Member] Starter | Points: 25

Up
0
Down
int Date = 20;
int Month = 7;
int Year = 2012;

DateTime _dt=new DateTime();
_dt =Convert.ToDateTime(Date.ToString() + "/" + Month.ToString() + "/" + Year.ToString());
Response.Write(_dt.ToShortDateString());


Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response