• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 364
  • Last Modified:

Use SQL to return date as a string

I need to return a datetime collumn value as a string.

The following is not correct.

string strRenewalDateSQL = "SELECT Convert(DateTime,DateAdd(month,1,LastPaidDate),101) AS RenewalDate ";
            strRenewalDateSQL += "FROM Subscriptions  WHERE UserID = '" + strUserID + "'";

What is the correct syntax?
0
Dovberman
Asked:
Dovberman
  • 3
1 Solution
 
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
0
 
DovbermanAuthor Commented:
I tried :

string strRenewalDateSQL = "SELECT CONVERT(varchar,  LastPaidDate, 101) AS LastPaidDate ";
            strRenewalDateSQL += "FROM Subscriptions  WHERE UserID = '" + strUserID + "'";

This does not return LastPaidDate as a string.

Please help. I found it difficult to try several of the many examples.

Please correct the syntax.

Thanks,
0
 
Anthony PerkinsCommented:
This last looks good to me.  What exactly is the problem/error message?
0
 
DovbermanAuthor Commented:
strUserID is not a valid user.

My code returned none as expected.

All is OK now.

Thanks,
0
 
DovbermanAuthor Commented:
Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now