Get the time from a DateTime Field


I looked at this post and it didn't work for me.


Trying to extract the time portion from a datetime field. ex  7:15:12 AM from    1/1/2008 7:15:12 aM

This is what I tried and neither functions give me the results I want....

 SELECT     DueTime, CONVERT(varchar, DueDate, 108) AS Expr1, SUBSTRING(CAST(DueDate AS varchar), 10, LEN(DueDate)) AS Expr2, CAST(DueDate AS varchar)
                       AS Expr3
FROM         TODO

Due Time                              Expr1                Expr2                         Expr3

1/1/2008 5:15:00 PM           00:00:00            12:00:00 AM              Jan 1 2008 12:00:00 AM

It seems Cast(DueDate as varchar) is the problem it converts the time to the default 12:00:00 AM

In the above example I want 5:15:00 PM


Tx in advance 


Mark as Answer if my post solved your problem
4/8/2008 10:08:50 AM 29906 articles. 0 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 33

Try -> convert(varchar(10), DueTime, 108)

Please click "Mark As Answer" if this hepled in solving your problem.
4/8/2008 10:23:24 AM

Try this one..

 select getdate(), convert (varchar(10), getdate() , 101) as [Date], convert (varchar(8), getdate(), 108) AS [Time]


Please remember to click "Mark as Answer" on this post if it helped you.
4/8/2008 10:45:11 AM

Similar Artilces:

how to get time value from datetime field?
dear friends..................                   i have a table like below..  name                                    date                                  &n...

Getting just time from datetime fields
I have some datetime fields that I want to get just the time out of. I know I can get the date by using "date(fieldname)", but I haven't found an equivalent "time(fieldname)". Is there a way to do this? I am using Infomaker 10. Thanks On 14 Nov 2005 13:37:12 -0800, Tom Minich wrote: >I have some datetime fields that I want to get just the time >out of. I know I can get the date by using >"date(fieldname)", but I haven't found an equivalent >"time(fieldname)". Is there a way to do this? I am using >Infomaker 10. ...

time limit validation on datetime field in sql
Hi How could I write some c# code which would check the length of time a data entry in a table has excisted i.e. i want to write a statement which checks if a value has been entered for more then 30 mins.e.g if datetimefield > 30 minutes do something{}  any help would be greatthanks!!  Keep a field in the table that keeps the time of insertion or updation. Update that field wherever you chnage some value. Now use that field value to know what was the last time some value was added in the tableVikram www.vikramlakhotia.comPlease mark the answer if it helped you ...

using time portion of DateTime field in SQL where clause
Does anyone know how to isolate and use just the time portion of a date timestamp field? I have two SQL tables, calendar_event start_timestamp - full date time stamp event_id base_schedule start_time - time stamp only I need a SQL statement that joins these two tables like this: select * from calendar_event, base_schedule where start_timestamp(time only) = start_time What's the format or syntax to use just the time stamp from the start_timestamp field? Thanks in advance for your help. Jim Are you trying to return just the time porti...

How can I get the amount of time between two datetime fields
I have to datetime fields and would like to create a procedure to calculate the difference between the two time portions of the daatetime entries 11/29/2006 12:00:00 PM 11/29/2006 05:00:00 PM Equals 5 Any help is appreciated.Thank youJackxxx Using System.DateTime objects, you can use the Subtract method to obtain a TimeSpan and then use either its Hours or TotalHours properties to obtain the difference in hours between them.RegardsDave try this: Dim d1 As Date = CType("11/29/2006 12:00:00 PM", Date) Dim d2 As Date = CType("11/29/2006 05:00:00 PM", Date) ...

Remove time when retriving value from datetime field from sql
Hello. I have a GridView where i display the date with the following format yyyy-MM-dd and i use DateFormatString="{0:d} on the textbox where the value is displayed with works great to the remove the time. But when i enter edit mode the time with is 00:00:00 is added aswell. I would like to not show this since i dont use the time when i send dates to my sql database. Is there anyway i can filter this out when i run my query? protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e){        TextBox t = (TextBox)GridView1.Rows[e....

how to get Time time difference in sql?
Could any one please tell me how to find time difference between two dates?   i have two fields in database as datetime data type.i need to get time difference between this two to do that? i use this one SELECT outdate, (datediff(mi, outtime, intime)  / 60.0)AS TimeUtilized FROM breaktime but it giving me results as 1.00000000 1.250000 3.00000 i jus want it to be 1 1.25 3 How to do this? Thanks for any help.     To find the time difference in days, hours, minutes. Try it, you can replace the dates with you column datetime.  select DATE...

save actual time in DateTime field in Sql Server 2005
Hi,        How could I save an actual time instead of 12:00:00 in sql table? I have a column in sql called submission_date of DateTime Datatype. This is how its storing now,  03/03/2008 12:00:00 How could that 12:00:00 be replaced with the actual time the user submits. This is coming from an application in ASP 2.0 C#.Consistency + Intensity = Success   When you save your date and time like 03/03/2008 13:26.01.423 it will save your time with date together into sql serverDon't forget to click "Mark as Answer" on the post(s) that hel...

.NET DateTime and SQL Server DateTime problem
.NET DateTime and SQL Server DateTime problem  I have the following if statement in an SQL stored procedure: IF (@Image = 1 AND @DateTimeUploaded = (SELECT ImageMainDateTime FROM Images WHERE UserID = @UserID))   The value of the @DateTimeUpdated variable was taken from the ImageMainDateTime field when the data was requested by a ASP.NET webpage and is passed back here when that page is submitted so I can compare what the DateTime was when the data was requested with what it is now, in other words I’m doing a concurrency check (I can’t use TimeStamp for many reasons, ...

Converting Date field and Time field to DateTime
D2007 We are converting data for a new customer. The old data has a field for 'updt-dt' which is a Date field. The old data has a field for 'updt-tm' which is an Integer field. We need to combine to have a DateTimeStamp. var OldDate, OldTime : TDateTime; looping FieldNameFrom := 'updt-dt'; FieldNameFrom2 := 'updt-tm'; if (not FieldByName(FieldNameFrom).IsNull) and (not FieldByName(FieldNameFrom2).IsNull) then begin Day := 0; Month := 0; Year := 0; ...

Compating DateTime field from sql table to DateTime Object
Hi. I have a SQL query that suppose to compare a given DateTime object to a datetime type coloumn : SELECT COUNT(*) FROM [QuestionnairesData] WHERE [SQClientUsername] = '" + Profile.UserName + "' AND [FillingDate] > " + Report.GetLastProductionReportDate(sqClient.SQCLIENTID)  the problem i get is on the last part of the select query. the DateTime object Report.GetLastProductionReportDate(sqClient.SQCLIENTID) gives me : 2/14/2007 15:49:04 PM and when i delete the time part it works well but i need to check for both date and time in this case. there is some issues with DateTime o...

Convert .NET DateTime format to SQL DateTime format
Hi!!I'd like to know if there is a function to convert the DateTime format used in C# (VS2005) : dd/mm/yyyy HH:mm:ss to the format used in SQL Databases: yyyymmdd HH:mm:ssThanks folks!...

DateTime unable to save in datetime field of SQL database
 Hi all, having a little problem with saving dates to sql databaseI've got the CreatedOn field in the table set to datetime type, but every time i try and run it i get an error kicked up  Error "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.The statement has been terminated."I've tried researching it but not been able to find something similar.  Heres the code: DateTime createOn = DateTime.Now;string sSQLStatement = "INSERT INTO Index (Name, Description, Creator,CreatedOn) values ('" + name + "','" + descri...

How can I update an MS SQL 7.0 datetime field with embedded sql
I have a datetime field in MS Sql 7.0 named Revised_Date. I can update this date with my datawindow but I can't update it with embedded sql. I have tried the following which doesn't work UPDATE dbo.employees SET revised_date = date() ; produces invalid function error UPDATE dbo.employees SET revised_date = 2000-07-31 ; which yeilds 05/17/05 which is incorrect date ld_date time ldt_datetime ld_date = today ldt_date = datetime(ld_date) UPDATE dbo.employees SET revised_date = :ldt_date; which yields error How can I accomplish this ? T...

Web resources about - Get the time from a DateTime Field -

Is there a JQuery plugin to convert UTC datetimes to local user timezone?
If I have a tag: <span class="utctime">2010-01-01 11:30 PM</span> I would like a jquery script or plug in to convert every utctime ...

Targetprocess 3.7.3: Epic unit for Bug/Story cards, new DateTime functions in Webhook plugin
Webhook plugin supports new DateTime functions AddDays(DateTime date, int days) – Returns a new date with the number of days added. The number ...

Common Pitfalls when working with DateTime’s
In .NET, the DateTime structure provides us wonderful functionality, but this seemingly simple structure can cause a lot of headaches if you ...

Parsing Twitter Date format to .Net DateTime
Recently when I needed to parse the twitter datetime format into a .Net DateTime I found this post on the web showing how to do it. However, ...

C Sharp (programming language) - Wikipedia, the free encyclopedia
(pronounced see sharp ) is a multi-paradigm programming language encompassing strong typing , imperative , declarative , functional , generic ...

1753 - Wikipedia, the free encyclopedia
Language: English Afrikaans አማርኛ العربية Aragonés Asturianu Aymar aru Azərbaycanca বাংলা Bân-lâm-gú Basa Banyumasan Беларуская ‪Беларуская (тарашкевіца)‬ ...

Coded Smorgasbord: Schizophrenic Haiku Comments and More
... writes Malcom StandardResponse UnSubscribeNewsletterUserAccount( string opTinGUID,string email, string sellingRegion, string source, DateTime ... - Welkom op de site van de provincie Limburg - Welkom_op_de_site_van_de_provincie_Limburg
visit wonen werken leven ontspannen infopunt home op trefwoord contactpersonen wegwijs sitemap print deze pagina Je bent hier: Contact ...

Simples Ideias. Por Nando Vieira.
Simples Ideias Siga-me no Twitter Junho/2012 Usando o Vagrant como ambiente de desenvolvimento no Windows ...

Resources last updated: 2/14/2016 12:09:57 AM