Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8020279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:38:46+00:00 2026-06-04T21:38:46+00:00

I am unable to get all the rows created today. I have used multiple

  • 0

I am unable to get all the rows created today. I have used multiple functions like getdate(), Cast, Convert, etc. but all in vain.

This is my basic query:

SELECT timeId
FROM table_roaster_time_table
WHERE (user_id = @user_id) AND (DATEDIFF(d, date, GETDATE()) = 0)

I want to get the timeId from the table table_roaster_time_table where userid will be provided and the date is today.

How do I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:38:49+00:00Added an answer on June 4, 2026 at 9:38 pm

    In order to keep any chance of using an index on the [date] column (even if one doesn’t exist today, it may in the future), try:

    AND [date] >= DATEADD(DAY, 0, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP))
    AND [date] <  DATEADD(DAY, 1, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP));
    

    If you’re using SQL Server 2008 or better, you can do something like this to shorten the code but still make use of an index on [date] if one exists:

    AND CONVERT(DATE, [date]) = CONVERT(DATE, CURRENT_TIMESTAMP);
    

    EDIT

    Since you seem to be confused why 3/6/2012 is March 6th and not June 3rd, I might also suggest that instead of manually inserting ambiguous date literals like '3/6/2012' into the database, you make the column a default such as:

    ALTER TABLE dbo.table_roaster_time_table
      ALTER COLUMN [date] DATETIME NOT NULL;
    
    ALTER TABLE dbo.table_roaster_time_table
      ADD CONSTRAINT df_date DEFAULT (CURRENT_TIMESTAMP)
      FOR [date];
    

    If you’re going to insert date literals then at least use a safe and unambiguous format, such as YYYYMMDD:

    INSERT dbo.table_roaster_time_table([date]) VALUES('20120603');
    

    Now there is no confusion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 tables with same columns, I need to get count of rows
can someone help me with this problem? I've used file_get_contents() to get all text
I am developing restful services with PHP Cake. I have developed all get services.
I have a table with multiple tbody's, each of which has a classed row,
We have a large application mainly written in SQL Server 7.0, where all database
As per https://stackoverflow.com/questions/3264227/relations-with-multiple-keys-in-doctrine-1-2 , I have two tables which (as I can't get it
I'm trying to search in a LDAP server all the users that have some
Here is my current code, http://jsfiddle.net/HRZ3D/2/ with it I have been unable to do
Possible Duplicate: Unable to get a list of installed Python modules How do I
I get the following output for many missing files: warning: Unable to read symbols

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.