Thursday, March 8, 2012

date format problem

HI

i AM GETTING PROBLEM WITH DATE FROMATS.

i have one query like this

select S.Trid,S.Dept,convert(varchar,S.Submittedon,107) as Submittedon,S.Subbyempno,S.Reqcurrently,
S.ManagersName,case S.Diffcost when '' then 'No' else 'Yes' end as Diffcostcenter,S.Status,S.Airline,
convert(varchar,S.Actionon,107) as Actionon,S.Actionby,S.reqemail,S.onbehalfof from status as S
where (S.Actionon=Convert(varchar,'5 Mar 2007',107))order by S.Submittedon

Actually here s.actionon=convert(varchar,'5 mar 2007',107)) here i am passing text control value taking from calender control

S.Actionon=Convert(varchar,'"+txtControl.Text.ToString()+"',107))";

this txtcontrol value is '5 Mar 2007'.

according to my table actionon field format is Mar 05, 2007.

When i m changing my query to this date format,it retreiving value.

But my query is generated dynamically based on selected value from control.

i want to change txtcontrol value to Mar 05,2007 format.

How to do this one.?

Thanks.

Hi,

You can use following

Convert.ToDateTime(txtControl.Text, 'mmm dd, yyyy');

And, you do not need to call method txtControl.Text.ToString() because Text property itself is a string type.

Thanks,

|||

Hi

I am getting error like

"Incorrect syntax near '.'."

When i used what u said.

Some syntax problem is there but I am not getting that problem.

Please help me.

Thanks.

|||

Hi,

Please try following :

public string FormatDate(string strDate) {try { Convert.ToDateTime("02/07/2007").ToString("MMM, dd yyyy"); }catch (Exception ex) {throw new Exception("Invalid string to format as date!!"); } }
Hope this works!!|||

Hi,

Please try following :

  
public string FormatDate(string strDate) {string result =string.Empty;try { result = Convert.ToDateTime("02/07/2007").ToString("MMM, dd yyyy"); }catch (FormatException) {throw new Exception("Invalid string to format as date!!"); }return result; }

Hope this works!!

No comments:

Post a Comment