Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
guys sorry to ask sql question


i have datetime format
like dd/mm/yyyy hh:mm:ss




i need it in dd/mm/yyy hh:mm:ss


its there in sp
Posted

This is not necessarily as simple as you think: a DateTime doesn't have a format - it is just a number of milliseconds since an arbitrary point in time. It only gets a format when you convert it to a string in some way! This could be in SQL via the CONVERT function: http://anubhavg.wordpress.com/2009/06/11/how-to-format-datetime-date-in-sql-server-2005/[^] or in the browser if you pass a DateTime direct to display items, or in your application code if you use ToString (either explicitly or implicitly).

To complicate things further, there are up to three different locales that could be involved here: The SQL server PC where any SQL code including stored procedures are run, the web server where any C# or VB code is run, and the client PC were the browser runs. Depending on where you do the conversion and how you do it, what format you will end up with!

Without knowing how you are working, we can't say "do this" and you will get the format you want (but the user might not want)
You need to look at exactly what you are doing before we could give you a definitive answer.
 
Share this answer
 
SELECT CONVERT(VARCHAR(6), GETDATE(), 101) + RIGHT(CONVERT(VARCHAR(10), GETDATE(), 101),3) + ' ' + CONVERT(VARCHAR(8), GETDATE(), 108) as FormatedDate
 
Share this answer
 
SQL
This can be done as follows :

select CONVERT(VARCHAR(10), GETDATE(), 103) + ' '  + convert(VARCHAR(8), GETDATE(), 14)

Hope it helps
 
Share this answer
 
please Try following

select CONVERT(VARCHAR(9), GETDATE(), 103)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900