| 
							 
 
						 | 
						
							
								
									
										 | 
									 
									
										 | 
									 
									
										
											| This example shows how date & time values can be stored separately using the SQL data types. |  
   Click here to copy the following block |   CREATE TABLE #DateAndTime ( DateOnly char( 8 ) not null     CHECK ( ISDATE( DateOnly ) = 1 And DateOnly LIKE REPLICATE( '[0-9]' , 8 ) ) , TimeOnly char( 8 ) not null     CHECK( ISDATE( TimeOnly ) = 1 And LEN( TimeOnly ) = 8 And         TimeOnly LIKE '[0-9][0-9]:[0-9][0-9]:[0-9][0-9]')  );
 
  INSERT INTO #DateAndTime VALUES( '20001009' , '09:00:00' ); INSERT INTO #DateAndTime VALUES( '20001008' , '19:00:00' ); INSERT INTO #DateAndTime VALUES( '20001008' , '03:00:00' ); INSERT INTO #DateAndTime VALUES( CONVERT( varchar, CURRENT_TIMESTAMP , 112 ) , '18:00:00' );
  SELECT * FROM #DateAndTime ORDER BY DateOnly , TimeOnly;
  GO SELECT CONVERT( datetime , DateOnly ) AS DateVal ,     CONVERT( datetime , TimeOnly ) AS TimeVal FROM #DateAndTime ORDER BY DateVal , TimeVal
 
 
  SELECT * FROM #DateAndTime WHERE DATEDIFF( hh , TimeOnly , '10:00:00' ) = 1 ORDER BY DateOnly , TimeOnly
 
 
  SELECT * FROM #DateAndTime WHERE DateOnly LIKE CONVERT( varchar , CURRENT_TIMESTAMP , 112 )
 
 
 
  SELECT * FROM #DateAndTime WHERE DATEDIFF( dd , DateOnly , CURRENT_TIMESTAMP ) = 0
  GO DROP TABLE #DateAndTime; GO |   
             
										 | 
									 
									
										| 
											
										 | 
									 
									
										| 
 | 
									 
								
							 
							
							
 
	
		| 
			Submitted By :
					Nayan Patel 
					 (Member Since : 5/26/2004 12:23:06 PM)
		 | 
	 
	
		  | 
	 
	
		| 
			 
				  
		 | 
		
			Job Description :   
			He is the moderator of this site and  currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. | 
	 
	
		| 
			View all (893) submissions by this author 
			(Birth Date : 7/14/1981 ) | 
	 
 
						 | 
						
						 |