GetDate() function does not return Current Date in SQL nor in VB.Net

Simon 446 Reputation points
2023-12-26T17:04:09.2466667+00:00

The GetDate() function until now, worked beautifully to return the current date, both in SQL as well as in VB.Net.

However, this code has stopped functioning and no longer returns the current date.

What can this mean?

When I try using a different code { fn CURDATE() }, in SQL it sometimes works, but when I want to AddDate function in SQL, I get a message that the returning date from the code { fn CURDATE() } is not a date, it's text. Even if I convert it to Date, it still generates the message that it is text and not a date.

Why did the GetDate function stop working?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,494 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,841 questions
{count} votes

Accepted answer
  1. Erland Sommarskog 120.4K Reputation points MVP Moderator
    2023-12-26T19:37:01.8766667+00:00

    This condition

    (Date = GETDATE())
    

    will only match if the Date column has a value which is exactly the same down to the millisecond as the current time.

    When I run SELECT getdate() right now, I see this:

    User's image

    But it will only take 3-4 milliseconds before that value changes.

    Assuming that the column Date only has a date and no time portion, you need to use:

    Date = CAST(getdate() AS date)
    

    By the way, that TOP(100) PERCENT in your query is fairly meaningless.

    By the way2, you had posted an Answer. Answers are for answers to the original question. You would only post an Answer if you find the solution yourself. I have converted you Answer to a comment.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.