Link to home
Start Free TrialLog in
Avatar of Dovberman
DovbermanFlag for United States of America

asked on

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?
Avatar of Raheman M. Abdul
Raheman M. Abdul
Flag of United Kingdom of Great Britain and Northern Ireland image

Avatar of Dovberman

ASKER

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,
ASKER CERTIFIED SOLUTION
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
strUserID is not a valid user.

My code returned none as expected.

All is OK now.

Thanks,
Thank you.