tags:

views:

97

answers:

1

T-SQL:

1(ANSI): convert(varchar(10),@DueDate, 102) < convert(varchar(10),getdate(), 102)

2(USA): convert(varchar(10),@DueDate, 101) < convert(varchar(10),getdate(), 101)

Notice that these will return different results when year is considered.

Why?

What's the difference? Why isn't the operator taking year into consideration when using #2?

+4  A: 

What are you trying to do? You're comparing varchars, there. Look at the output from these statements:

print convert(varchar(10), getdate(), 101)
print convert(varchar(10), getdate(), 102)

That prints this:

01/14/2009
2009.01.14

Comparing the first form is only really going to be checking to see if the month of one date is less than the month of the current date.

Is there a reason you need to convert the dates to varchar? Why not compare them directly?

@DueDate < getdate()
Matt Hamilton