Click here to Skip to main content
16,023,224 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
hi..

i'm having a table with columns source,destination,date and time,customer id..
but i'l give source,destination and date alone as input..where as i want the time as output..is it possible to get time on particular date??
Posted
Comments
Prasad_Kulkarni 13-Jan-12 7:19am    
please elaborate some more,if possible with source code..

There is no Time datatype, it is stored as part of the DateTime, which is held in terms of milliseconds since an arbitrary point in teh past.
Depending on where you want to do this, you can retrieve the DateTime and format it for display in your ASP code, using the DateTime.ToString Method with the parameter "hh:mm" or "HH:mm" (there is a list of the format specifiers here: Formatting a DateTime for display - format string description[^])
or if you want to do it in SQL , you can return it as int, or string:

SQL
DECLARE @DT as Datetime
SET @DT='2011-01-13 12:28'
SELECT DATEPART(hour, @DT), DATEPART(minute, @DT), CAST(DATEPART(hour, @DT) AS VARCHAR(2)) + ':' + CAST(DATEPART(minute, @DT) AS VARCHAR(2))
 
Share this answer
 
It is possible to get time along with date, but it will be the default value. Example:
SQL
Create table test_table (Idfield int, dateOne datetime, dateTwo smalldatetime);
-- input only date field..
insert into test_table values (1, '10/10/2011','10/11/2011');
select * from test_table 
--Output will be 
1	2011-10-10 00:00:00.000	2011-10-11 00:00:00
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900