Dovberman
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(m onth,1,Las tPaidDate) ,101) AS RenewalDate ";
strRenewalDateSQL += "FROM Subscriptions WHERE UserID = '" + strUserID + "'";
What is the correct syntax?
The following is not correct.
string strRenewalDateSQL = "SELECT Convert(DateTime,DateAdd(m
strRenewalDateSQL += "FROM Subscriptions WHERE UserID = '" + strUserID + "'";
What is the correct syntax?
Detailed with examples follow: http://www.sqlusa.com/bestpractices/datetimeconversion/
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,
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
strUserID is not a valid user.
My code returned none as expected.
All is OK now.
Thanks,
My code returned none as expected.
All is OK now.
Thanks,
ASKER
Thank you.