time format in SQL Server

前端 未结 7 1734
心在旅途
心在旅途 2020-12-04 01:20

Does anyone know how can I format a select statement datetime value to only display time in SQL Server?

example:

Table cuatomer
id   name   datetime
         


        
7条回答
  •  情深已故
    2020-12-04 02:08

    You might be able to use:

    select
    
    convert(varchar,getdate(),114)
    

    You might be able to manually construct the query like:

    string query = string.Format("INSERT INTO test (DateOnlyField, TimeOnlyField) VALUES ('{0}', '1899-12-30 {1}')", DateTime.Today.ToShortDateString(), TimeString)
    

    I dunno if this might work to:

    Create Table Schedule( ScheduleID Integer Identity, ScheduledTime DateTime )
    
    Go
    
    Insert Into Schedule( ScheduledTime ) Values( '10:15:00 AM' )
    
    Go
    
    Select ScheduledTime As DBScheduledTime, Convert( VarChar( 10 ), ScheduledTime, 114 ) As ScheduledTime
    
    From Schedule
    
    Go
    
    Drop Table Schedule
    
    Go
    

提交回复
热议问题