Solved

Use SQL to return date as a string

Posted on 2011-02-20
5
344 Views
Last Modified: 2012-05-11
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
Comment
Question by:Dovberman
  • 3
5 Comments
 
LVL 18

Expert Comment

by:Raheman M. Abdul
ID: 34939108
0
 

Author Comment

by:Dovberman
ID: 34939225
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
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 250 total points
ID: 34939346
This last looks good to me.  What exactly is the problem/error message?
0
 

Author Comment

by:Dovberman
ID: 34939473
strUserID is not a valid user.

My code returned none as expected.

All is OK now.

Thanks,
0
 

Author Closing Comment

by:Dovberman
ID: 34939476
Thank you.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now