Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Single month date to two month date

Author  Topic 

TPie9
Yak Posting Veteran

67 Posts

Posted - 2010-09-23 : 12:23:45
I have 2 tables were the period columns are differnt and I can't link them so I was wondering how to change the format to reflect 2 digits for the month. The first table shows the date as '1/01/2010' and the second table shows the date as '01/01/2010'. How do I convert the date from the 1st table to show as '01/01/2010'? Basically add a zero in front of the one.

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-09-23 : 12:29:25
no need of that. if you want to do comparison first convert it to datetime format. I'm not sure your format is mm/dd/yyyy or dd/mm/yyyy so use an appropriate style value based on your format

http://msdn.microsoft.com/en-us/library/ms187928.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-09-24 : 06:14:34
Make sure to read this
http://beyondrelational.com/blogs/madhivanan/archive/2010/06/03/understanding-datetime-column-part-ii.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-09-24 : 06:25:17
Since your format is obviously mm/dd/yyyy you can use the following convert to datetime and then compare the values.
for example
where convert(datetime,your_datecolumn1,101) = convert(datetime,your_datecolumn2,101)


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -