Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Guid for a specific DateTime (i.e. not for Now) #14

Closed
pethopal opened this issue Feb 10, 2020 · 1 comment
Closed

Generate Guid for a specific DateTime (i.e. not for Now) #14

pethopal opened this issue Feb 10, 2020 · 1 comment
Labels

Comments

@pethopal
Copy link

Hi, I used RT.Comb succesfully many years. (In SQL Server these Guids can even be used as Primary Keys)

For efficient querying purposes can I generate a Guid for a Specific DateTime.
(Note I will use it for only in SQL Where '>', '<' clause.

Thanks...

@richardtallent
Copy link
Owner

That's great to hear! I use them for PKs in a number of projects as well in MSSQL / AzureDB projects.

You can query for COMBs falling within a date range. If your SQL is being dynamically generated from .NET code, you can just create the boundary COMBs for your query parameters like this (untested):

var fromComb = provider.Create(Guid.Empty, startDateTime);
var toComb = provider.Create(new Guid("FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF", endDateTime);

If you're looking to convert from a date range to a COMB query directly in T-SQL (for example, feeding datetime values to a stored procedure and having it search on the COMB values), you can use the T-SQL examples shown in the README for your chosen provider to combine the "empty" and "full" GUID values with your start and end datetime values, respectively.

Either way, you'll be able to take full advantage of indexing. It's not as efficient as a "real" datetime column and index, of course, but it's fine for a wide range of use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants