Question :
This is my query:
select c.InFavourOf as name,
c.ChequeDate,
p.Amount as amount,
m.No as CNo
from Cheque c
inner join PaymentDetail p
on c.MasterID= p.PaymentMasterID
inner join PaymentMaster m
on p.ID=m.ID
Result:
I want the date values in column ChequeDate
formatted as dd mm yyyy
without the time part.
How can I do that?
Answer :
The convert function can do that. And if you want dd mm yyyy
format 103 (with /
separator) or 104 (with .
separator) would be fine.
select c.InFavourOf as name,
convert(varchar(10), c.ChequeDate, 103),
p.Amount as amount,
m.No as CNo
from Cheque c
inner join PaymentDetail p
on c.MasterID= p.PaymentMasterID
inner join PaymentMaster m
on p.ID=m.ID
If you want space
separator, use replace function.
replace(convert(varchar(10), c.ChequeDate, 103), '/', ' ')
select c.InFavourOf as name,
CONVERT(VARCHAR(10),c.ChequeDate, 103) as ChequeDate ,
p.Amount as amount,
m.No as CNo
from Cheque c
inner join PaymentDetail p
on c.MasterID= p.PaymentMasterID
inner join PaymentMaster m
on p.ID=m.ID
If the variable you want to display as date and not the time you can use the convert function that others have shown or you can format your own string with other SQL-SERVER functions
select c.InFavourOf as name,
DATEPART(DAY, c.ChecqueDate) AS day, DATEPART(MONTH,c.ChecqueDate) AS MONTHH, DATEPART(YEAR, c.ChecqueDate) AS YEAR as ChequeDate ,
p.Amount as amount,
m.No as CNo
from Cheque c
inner join PaymentDetail p
on c.MasterID= p.PaymentMasterID
inner join PaymentMaster m
on p.ID=m.ID
Hopefully at least one of the answers here will put you in the right track 🙂