Sunday, February 19, 2012

how to get FromDate and ToDate values from database

Hi All,

I have to fetch FromDate and Todate values from the table like this.Suppose Fromdate value is 02-Feb-2007 and Todate Value is 04-Feb-2007,then my need is to get the date value like this.....Feb 2-4,2007or 2-4 Feb,2007.Can anybody know the syntax or code?.I am using sql Server.

Thanks and Regards

What dataType are you storing in your DB? SmallDateTime...? Are you storing these dates in two fields?

|||

Datatype is date for sqlserver and yes these dates are stored in two different fields like 8/4/2007 12:00:00 AM.

|||

Here you go. Assuming your columns are named from_date and to_date. This also assumes that your dates are within the same month and year, as per your example.

Selectconvert(varchar(2),DatePart(day, from_date)) +'-' +convert(varchar(2),DatePart(day, to_date))+' '+substring(convert(varchar(12), to_date, 106), 4, 8)from [yourtable]

No comments:

Post a Comment