Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Random date generation

Author  Topic 

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2008-02-23 : 04:14:10
I need to generate random data (say, 100 sets) for testing date manipulation scripts before releasing them on 'live' data.

Dates prior to 2000 need to be in the format YYMMYY and dates greater than 1999 need to be in the format YYYMMDD where 102 = 2002, 104 = 2004 etc.

The dates need to be valid, but I'm not sure how to go about this (right now) as my sql knowledge is rudimentary. Any pointers would be much appreciated.

ayamas
Aged Yak Warrior

552 Posts

Posted - 2008-02-23 : 08:19:40
quote:

Dates prior to 2000 need to be in the format YYMMYY and dates greater than 1999 need to be in the format YYYMMDD where 102 = 2002, 104 = 2004 etc.



I didnt get it.
You said dates prior to 2000 should be YYMMYY(never heard of this kind of format) & dates greater than 1999 should be in
YYYMMDD.But I think both the conditions are same.
Go to Top of Page

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2008-02-23 : 09:00:50
My apologies. It should be dates prior to 2000 are YYMMDD and dates after 1999 are YYYMMDD with the years prefixed with 10 ...

After 18+ hours of coding, my re-reading skills are running on empty.

Need sleep .....zzzz .....
Go to Top of Page

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2008-02-23 : 14:16:56
Ah, now I've had some sleep I've realised that I can do this easliy in php.

Sorry for posting.
Go to Top of Page

ayamas
Aged Yak Warrior

552 Posts

Posted - 2008-02-23 : 14:33:26
Well I guess this is what you want.

declare @date as datetime
set @date='10-jan-1998'


select case when datepart(yy,convert(datetime,Dates,111))>='1999' then Dates + ' ' + '10'
when datepart(yy,convert(datetime,Dates,111))<'2000' then Dates end as Dates from
(
select convert(varchar,dateadd(dd,number,@date),111)as Dates
from master.dbo.spt_values where type='p'
)t

Go to Top of Page

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2008-02-23 : 16:14:51
Many thanks for your reply.
Go to Top of Page
   

- Advertisement -