By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,377 Members | 1,330 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,377 IT Pros & Developers. It's quick & easy.

DateFormat

P: 8
I want to convert a date(which is in the DDMMYYYY format) into the MMDDYYYY format in sql query.below is my query but its not working??
Do anyone have any idea???

declare @s char(10)
set @s = '21/04/2008'
select convert(char(10),@s,101)
Apr 21 '08 #1
Share this Question
Share on Google+
2 Replies


deepuv04
Expert 100+
P: 227
I want to convert a date(which is in the DDMMYYYY format) into the MMDDYYYY format in sql query.below is my query but its not working??
Do anyone have any idea???

declare @s char(10)
set @s = '21/04/2008'
select convert(char(10),@s,101)
Hi,
Try declaring @s as datetime and set the value as '2008-04-21'

then your query will execute currectly

Expand|Select|Wrap|Line Numbers
  1. declare @s DATETIME 
  2. --set @s = '21/04/2008'
  3. set @s = '2008-04-21'
  4. select convert(char(10),@s,101)
  5.  
  6.  
Apr 21 '08 #2

ck9663
Expert 2.5K+
P: 2,878
I want to convert a date(which is in the DDMMYYYY format) into the MMDDYYYY format in sql query.below is my query but its not working??
Do anyone have any idea???

declare @s char(10)
set @s = '21/04/2008'
select convert(char(10),@s,101)

Try:

Expand|Select|Wrap|Line Numbers
  1. declare @s varchar(10)
  2.  
  3. set @s = '21/04/2008'
  4.  
  5. select convert(varchar(20), convert(datetime, @s, 103),101)
-- CK
Apr 21 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.