0

The European format of dd/mm/yy hh:mm isn't supported by SQL, is there any way to create one? I am trying to return it in a stored procedure like so:

ALTER PROCEDURE dbo.GetMeetingByCustomerID
    @CustomerID nvarchar(50),

AS

    SELECT  ProfessionalID, MeetingDate, Cost, HasReview, Approved
    FROM     Meeting
    WHERE  (CostumerID = @CostumerID)
    ORDER BY MeetingDate ASC
    RETURN

The only problem is that it returns it in the wrong format. Is there a way to create a new one? Thanks. EDIT: I solved this. what I did was:

 MeetingDate = DateTime.Parse(Meetings.Tables[0].Rows[i][1].ToString());
                string d = MeetingDate.ToString("hh:mm dd/MM/yy");        
7
  • 4
    Why do it in SQL? Do it in the application. What version of SQL Server (I am assuming that's what you are using)? Commented Mar 27, 2013 at 21:28
  • return it as a TO_CHAR with whatever format you like. Commented Mar 27, 2013 at 21:29
  • 1
    Agree with Oded. Return an actual date, and format it in the application. Commented Mar 27, 2013 at 21:29
  • 1
    Most db's have date formatting functions. Knowing the db engine you are using would help find them. Commented Mar 27, 2013 at 21:30
  • 1
    Formatting a date is responsability of the application that gets the date back from your query, unless you try to return a character strings instead of a date Commented Mar 27, 2013 at 21:31

1 Answer 1

1

First of all, I believe it's incorrect to format date/time in SELECT requests. But if you really need it, use CAST/CONVERT (if you use MS SQL) and remove unused symbols like:

SELECT ProfessionalID, CONVERT (varchar(5), MeetingDate, 108) AS MeetingDateString, Cost, HasReview, Approved
FROM     Meeting
WHERE  (CostumerID = @CostumerID)
ORDER BY MeetingDate ASC
Sign up to request clarification or add additional context in comments.

3 Comments

You'll want to alias the result of the CONVERT.
How can I do it in the application? im using c# and asp.net
@MichaelSallmen, yes sure, an alias should be there. I fixed my answer. Htusa, formating depends on the control type you're going represent this information in. I'd recommend to go to msdn.microsoft.com/en-us/library/8kb3ddd4.aspx to get general information on formatting date/time in C#

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.