Help: ResulSet.getDate(int col) rounds time to 12:00AM

Using Microsoft SQL Server 7, I execute the following code:
CREATE TABLE Test (RegDate DATETIME, SmallDate SMALLDATETIME)
INSERT INTO Test (RegDate, SmallDate) VALUES ('1/1/2000 5:37 AM', '1/1/2000 5:37 AM')
SELECT * FROM TestThis is the output that I get back:RegDate                     SmallDate                  
2000-01-01 05:37:00.000     2000-01-01 05:37:00Ok, it looks good so far... now let me query this table with JDBC://just a snippet... I already have a connection, and a statement (stmt)
SimpleDateFormat format = new SimpleDateFormat("M/dd/yyyy h:mm:ss a");
ResultSet rs = stmt.executeQuery("SELECT * FROM Test");
while(rs.next()) {
    System.out.println("RegDate is " + format.format(rs.getDate(1)));
    System.out.println("SmallDate is " + format.format(rs.getDate(2)));
}The output from the java code is:RegDate is 1/1/2000 12:00 AM
SmallDate is 1/1/2000 12:00 AMThe month, day and year are correct but the hours and minutes are 12:00 AM. How can I get the hours and minutes?
Thanks,
jay

Okay, I did some reading and I learned that java.sql.Date will always show 12:00 AM (aka zero). There is a class called java.sql.Time which should take care of the time.
I still don't know how to get the Date and time from a ResultSet though. I can call ResultSet.getDate(int col) or ResultSet.getTime(int col) but not both (after getting a column's value, subsequent calls return null). I even tried getting raw data and parsing it via ResultSet.getBytes() and ResutSet.getBinaryStream()... common sense tells me that there's got to be a cleaner, simpler way to do this. Surely I'm not the first person who wanted to read the date and time from a SQLServer DATETIME column!
thanks again

Similar Messages

  • Why does getdate() function return same time value for multiple select statements executed sequentially

    When I run the following code
    set nocount on
    declare @i table(id int identity(1,1) primary key, sDate datetime)
    while((select count(*) from @i)<10000)
    begin
    insert into @i(sDate) select getdate()
    end
    select top 5 sDate, count(id) selectCalls
    from @i
    group by sDate
    order by count(id) desc
    I get the following results. 
    sDate                   selectCalls
    2014-07-30 14:50:27.510 406
    2014-07-30 14:50:27.527 274
    2014-07-30 14:50:27.540 219
    2014-07-30 14:50:27.557 195
    2014-07-30 14:50:27.573 170
    As you can see the select getdate() function returned same time up to the milisecon 406 time for the first date value.  This started happening when we moved our applications to a faster server with four processors.  Is this correct or am I
    going crazy?
    Please let me know
    Bilal

    Observe that adding 2 ms is accurate only with datetime2.  As noted above, datetime does not have ms resolution:
    set nocount on
    declare @d datetime, @i int, @d2 datetime2
    select @d = getdate(), @i = 0, @d2 = sysdatetime()
    while(@i<10)
    begin
    select @d2, @d, current_timestamp, getdate(), sysdatetime()
    select @d = dateadd(ms,2,@d), @i = @i+1, @d2=dateadd(ms,2,@d2)
    end
    2014-08-09 08:36:11.1700395 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    2014-08-09 08:36:11.1720395 2014-08-09 08:36:11.173 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    2014-08-09 08:36:11.1740395 2014-08-09 08:36:11.177 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    2014-08-09 08:36:11.1760395 2014-08-09 08:36:11.180 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    2014-08-09 08:36:11.1780395 2014-08-09 08:36:11.183 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    2014-08-09 08:36:11.1800395 2014-08-09 08:36:11.187 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
    DATE/TIME functions:
    http://www.sqlusa.com/bestpractices/datetimeconversion/
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Rounding time field to nearest half hour

    Post Author: fiscyn
    CA Forum: Formula
    Is there a way to round a time field?
    For example,  if a time field is from 9:01 to 9:14  I want it to round back to 9:00;  
    9:15 to 9:29  or 9:31 to 9:44   I want either option to round to 9:30
    and 9:45 to 9:59 I want to round to 10:00.
      I want to keep the original time and have the rounded time listed next to it.    Also I want this for a 24 hour clock, military time.  Don't know if that makes a difference.
    Any help is appreciated.
    Thanks.

    Post Author: fiscyn
    CA Forum: Formula
    I'm slowly getting this to work.    Just a couple problems,  minor I hope.
    I used the CTime function and used the rounding formulas for minutes and hours as you suggested.  It works great.   But the results for the hours come out as 12.00  and the minutes as 30.00 or 0.00.   How do I drop the decimals?   I tried the totext, 0 function,  but the numbers don't line up correctly.   If the hour is 9.00,  it drops the zero place holder.   So if 9 and 10 are lined up,  the 9 is above the 1 instead of the 0.  
      It works fine for the minutes except I end up with 0 instead of 00.   Any suggestions?
    I greatly appreciate the help so far.   Thank you.

  • Rounding time to nearest hourly quarter

    I have several records like
    2/19/2010 1:25:46.000000 PM
    2/19/2010 1:40:46.000000 PM
    2/19/2010 1:55:46.000000 PM
    2/19/2010 2:10:46.000000 PM
    I want to round them off to the nearest quarter like
    2/19/2010 1:30:00.000000 PM
    2/19/2010 1:45:00.000000 PM
    2/19/2010 2:00:00.000000 PM
    2/19/2010 2:15:00.000000 PM
    Any ideas how I would do that? a trunc(col,'mi) only lets me round it to the minute..
    Note that records are not necessarily in the 5 minute interval difference it can also be 7 minute difference or 4 minute difference from the nearest quarter...
    so I can also have records like
    SysUpTime     2/19/2010 10:31:00 PM
    SysUpTime     2/19/2010 10:57:00 PM
    SysUpTime     2/19/2010 11:31:00 PM
    etc.
    Edited by: zebango on Mar 9, 2010 4:16 PM

    Solomon Yakobson wrote:
    But OP asked for "*Rounding* time to nearest hourly quarter". Same applies to Aketi's solution which, BTW, which always bumps it up to next 5 min.In which case, just substitute "Round" for "Floor"!
    Although thinking about it, you'd probably want to add seconds into the mix:
    with table_x as (select to_timestamp('11/03/2010 11:45:39', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 11:52:29', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 11:52:30', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 11:52:31', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 12:00:01', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 12:07:29', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 12:07:31', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 13:22:10', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 13:22:40', 'dd/mm/yyyy hh24:mi:ss') t from dual)
    select t,
           trunc(t, 'hh') + ROUND((to_char(t, 'mi') + (to_char(t, 'ss')/60))/15)*15/1440 nearest_15_min
    from   table_x
    T                                NEAREST_15_MIN      
    11/03/2010 11:45:39.000000       11/03/2010 11:45:00 
    11/03/2010 11:52:29.000000       11/03/2010 11:45:00 
    11/03/2010 11:52:30.000000       11/03/2010 12:00:00 
    11/03/2010 11:52:31.000000       11/03/2010 12:00:00 
    11/03/2010 12:00:01.000000       11/03/2010 12:00:00 
    11/03/2010 12:07:29.000000       11/03/2010 12:00:00 
    11/03/2010 12:07:31.000000       11/03/2010 12:15:00 
    11/03/2010 13:22:10.000000       11/03/2010 13:15:00 
    11/03/2010 13:22:40.000000       11/03/2010 13:30:00 

  • Since itunes and apple tvs latest update I have had problem wtching movies on apple tv via my itunes can any one help, movie takes a very long time to load sometimes never, it use to work really well, whats going on please help?

    Since itunes and apple tvs latest update I have had problem wtching movies on apple tv via my itunes can any one help, movie takes a very long time to load sometimes never, it use to work really well, whats going on please help?

    You might find useful information in item D1 of Time Machine Troubleshooting.

  • HT201210 (The iPhone "Named" cannot be restored at this time because the iPhone software update server could not be contacted or is temporarily unavailable.) can anyone help me with this issue, every time i try to restore it will come up like this error m

    (The iPhone "Named" cannot be restored at this time because the iPhone software update server could not be contacted or is temporarily unavailable.)
    can anyone help me with this issue, every time i try to restore it will come up like this error message.

    Restore the iPhone when connected to iTunes by cable.
    Still the same TS1275?
    Is your iPhone jailbroken?
    Or
    Has your computer ever been used to jailbrake or downgrade (Tinyumbrella) any iPhone?

  • TS4268 Please help, I can't find face time and Siri icon on my mini ipad? Just bought it I have the IMessage icon and is able to use it.

    Please help, I can't find face time and Siri icon on my mini ipad? Just bought it I have the IMessage icon and is able to use it.

    There is no Siri "icon". You access Siri using the Home button. But you may need to turn it on: Settings App > General > Siri. http://support.apple.com/kb/HT4992
    Same for the FaceTime function (but if it is ON, there will be an icon): Settings App > FaceTime > [turn it on and set you Apple ID. http://support.apple.com/kb/HT4319

  • Having problem buying online.need your help since it's my first time here.apple is asking for my billing address but when i enter my address here in qatar,it's saying i should enter a valid zip code within the u.s.does it mean i can't buy online

    having problem buying online.need your help since it's my first time here.apple is asking for my billing address but when i enter my address here in qatar,it's saying i should enter a valid zip code within the u.s.does it mean i can't buy online even if it wil be shipped within u.s. only?

    To buy in for delivery in Qatar, you should be starting from the Apple Qatar site:
    http://www.apple.com/qa/
    Do you have an Apple-ID? if you do, then you should not have to enter your Address again, and may be able to sidestep the US Zip Code issue.

  • Help menu options change all the time - repair install always shows

    After installing Acrobat X, I noticed the Help menu options change all the time.  The repair install option is always present and sometimes the deactivate option is present but grreyed-out, somtimes it is enabled and most of the time it doesn't even show up.  I have the full version purchased from a major online retailer.

    I should add the following: The Sound control panel will not even let me click on the "Show volume in Menu Bar" check box.
    I just now installed the latest Brother control panel (Leopard compatible) and it DOES appear in the menu bar.

  • I Need Help for the popup message every time I go to safari: "Warning! Old version of Adobe Flash Player detected. Please download new version."???

    I Need Help for the popup message every time I go to safari: "Warning! Old version of Adobe Flash Player detected. Please download new version."???

    If you are talking about Safari on the iPad, there is no version of Adobe Flash for iOS and there never has been. Clear Safari, close the app and reset the iPad.
    Go to Settings>Safari>Clear History and Website Data
    In order to close apps, you have to drag the app up from the multitasking display. Double tap the home button and you will see apps lined up going left to right across the screen. Swipe to get to the app that you want to close and then swipe "up" on the app preview thumbnail to close it.
    Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider if it appears on the screen - let go of the buttons. Let the iPad start up.
    If you are talking about Safari on your Mac, you are in the wrong forum. But I would still clear the cache, quit Safari and restart the Mac.

  • I have accidentally deleted off my Mac a preferences file for Adobe photoshop and now the program cannot initialize. I have talked to Apple and then say that if Adobe can isolate the file they can help me restore it from my time machine. How do I isolate

    I have accidentally deleted off my Mac a preferences file for Adobe photoshop and now the program cannot initialize. I have talked to Apple and then say that if Adobe can isolate the file they can help me restore it from my time machine. How do I isolate the file ?

    Do you have the path to this file and name of this file?

  • I m having issues with the phone which i made a recording but the customer care support in our place donot seem to be of much help. i have told them nuumerous times that for better understanding i have made a video of it but no response.. really disspoint

    i m having issues with the phone which i made a recording but the customer care support in our place donot seem to be of much help.
    i have told them nuumerous times that for better understanding i have made a video of it but no response..
    really disspointed with your customer support.
    i have uploaded them in google docs..links below.. t
    he first one happened on 30th of april 2014   https://docs.google.com/file/d/0B6z0lUXVGPGrc0tXNnZFaDQ3WDg/edit
    the second happened today. i called customer care but no satisfactory respose either.  https://docs.google.com/file/d/0B6z0lUXVGPGrSldEeWQ3aGFhaDA/edit
    who is going to help me out and atleast pay attention to what my problem is. apple seems to ignore my attempts to show them what is the problem... the dont even want to see the videos.. !! disgusting.
    its still under warrenty. please help.

    Take your iPhone to an Apple Store or authorized service center in the country where you purchased the iPhone and they will look at it and replace it under warranty if applicable.
    If you cannot take it person contact them to determine how to send them your phone.
    You can't expect them to replace your iPhone without first examining it.

  • Help to create item at run time

    Hi all
    Please help to create item at run time
    I want to create item at run time
    is it Possible ???
    thank you

    Hi,
    As mentioned several times above, you cannot use Forms for displaying dynamic columns. So, you have two options (AFAIK).
    1. Create maximum number of items and set their visibility off based on the user input.
    2. Create a PJC (may be by extending JTable), and display dynamic columns (i feel it is a bit complicated and not straight forward as it sounds). Here is a [simple howto|http://sheikyerbouti.developpez.com/forms-pjc-bean/first-bean/first_bean.pdf] to build the PJC.
    -Arun

  • Can i change ios 8 to ios 7.1.2 please help me my mobile stuck every time

    can i change ios 8 to ios 7.1.2 please help me my mobile stuck every time
    <Email Edited by Host>

    No, there is no way to downgrade iOS.

  • HT1349 Since I switch to iCloud, I cannot sent emails from my iPhone. Any quick help? I don't have time to go through the Apple web of "Solutions" thanks in advance! Anyone! Thanks.

    Since I switched to iCloud, I cannot sent emails from my iPhone. Any quick help? I don't have time to go through the Apple web of "Solutions" thanks in advance! Anyone! Thanks.

    You can't send emails? Do you receive an error message when you try to send them? Have you done ANY troubleshooting on the device at all? If you don't have time to try things yourself, it will almost certainly take longer to try it in here.

Maybe you are looking for

  • Can my family of 4 have different apple ID's and share purchases?

    I am running into trouble with apps that require a different apple ID to differentiate between each family member because we have all been associating each of our email addresses with only my apple ID. Can each of us in our family have a different ap

  • Report Selection Formula Error with Crystal Reports 2008 SP3 Fix Pack 3.5

    Hello, My name is Carlos, and I would like to report a defect found in the Crystal Reports 2008 SP 3 Fix Pack 3.5 Runtime that is affecting the majority of our reports.  As well, I would like to ask if there is a simple workaround that does not invol

  • Issue in getting user when Forms 6i is embedded in Portal

    Hi, For a portal project , we are embedding Forms 6i with the portal. portal30.wwctx_api.get_user function is used to get the user from the session.However Forms is not able to get this and returns 'PUBLIC' . I guess Forms creates its own new session

  • DB view/table being accessed

    Is there a system/database level trigger that will tell me which view/table is being accessed? I just need to know if a specific view/table is being queried. Thanks.

  • Minimize button doesn't appear.

    The minimize button doesn't appear in Photoshop CS for Mac, and I don't know how minimize the program and it's harming my workflow. I'm a new user on Mac.