| Author |
Message |
tkdennis
Joined: 29 Feb 2008 Posts: 74
|
Posted: Thu Jun 03, 2010 2:12 am Post subject: Customize DateTime Generator MinValue/MaxValue |
|
|
I'm trying to use the DateTimeGenerator.xml in the UserExample\config directory to make an specific date range generator. How do I convert a date to the MinValue and MaxValue numbers? Is there a formula to use?
| Code: |
<generator
type="RedGate.SQLDataGenerator.Generators.DateTime.DateTimeGenerator"
name="DateTimeGenerator"
description="DateTimeGenerator..."
category="MyApp">
<property name="MinValue">633032064000000000</property>
<property name="MaxValue">633346560000000000</property>
|
Thanks,
Traci |
|
| Back to top |
|
 |
Brian Donahue
Joined: 23 Aug 2004 Posts: 6369 Location: Red Gate Software
|
Posted: Fri Jun 04, 2010 1:27 pm Post subject: |
|
|
The minimum and maximum value for the DateTime generator should be expressed in .NET Ticks. If you're stuck, it looks like SQL Server has a handy function to convert a datetime expression to ticks: dbo.DateTimeToTicks
http://www.codeproject.com/KB/database/DateTimeToTicks.aspx
I hope this works for you. _________________ Brian Donahue
Technical Support
Red Gate Software Ltd.
44 (0)870 160 0037 ext 8521
US and CAN 1-866-RED GATE ext 8521 |
|
| Back to top |
|
 |
tkdennis
Joined: 29 Feb 2008 Posts: 74
|
Posted: Fri Jun 04, 2010 7:08 pm Post subject: |
|
|
That worked perfectly - thank you!
I'm copying the code I used from the article and the comments, if anyone else needs it:
| Code: |
CREATE FUNCTION [dbo].GetTicksFromTime (@d datetime)
RETURNS BIGINT AS BEGIN
RETURN (DATEDiff(s, '20060823', @d) + 63291888000 ) * 10000000
END
GO
CREATE FUNCTION dbo.GetTimeFromTicks (@Ticks BIGINT)
RETURNS DATETIME AS BEGIN
DECLARE @Days BIGINT
DECLARE @DaysBefore1753 BIGINT
DECLARE @TimeTicks BIGINT
DECLARE @Seconds BIGINT
SET @Days = @Ticks / CONVERT(BIGINT,864000000000)
SET @DaysBefore1753 = CONVERT(BIGINT,639905)
SET @TimeTicks = @Ticks % CONVERT(BIGINT,864000000000)
SET @Seconds = @TimeTicks / CONVERT(BIGINT,10000000)
RETURN DATEADD(s,@Seconds,DATEADD(d,@Days - @DaysBefore1753,CONVERT(DATETIME,'1/1/1753')))
END
GO
DECLARE @TestDate datetime
SET @TestDate = GETDATE()
select @TestDate, dbo.GetTicksFromTime(@TestDate), dbo.GetTimeFromTicks(dbo.GetTicksFromTime(@TestDate))
SET @TestDate = '2/29/1992 12:34:56'
select @TestDate, dbo.GetTicksFromTime(@TestDate), dbo.GetTimeFromTicks(dbo.GetTicksFromTime(@TestDate))
GO
|
|
|
| Back to top |
|
 |
|
|
All times are GMT + 1 Hour
|
| Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group