cancel
Showing results for 
Search instead for 
Did you mean: 

DateTime milliseconds rounding

SOLVED
mbeckham
New Contributor

DateTime milliseconds rounding

Hi,  I'm hoping there is someone who may have a solution to my problem.

I have a SQL database column ActionDateTime (datetime) with the following value: 

mbeckham_0-1609730406465.png

The value displayed on the website is :

mbeckham_1-1609730531065.png

When I verify the ActionDateTime   ( website table vs database table)

 

dateActioned = aqConvert.DateTimeToFormatStr(Qry3.FieldByName("ActionDateTime").Value, "%d/%m/%Y %H:%M");

aqObject.CheckProperty(Table.rows.item(rowIdx).cells.item(3), "innerText", cmpEqual, dateActioned);

 

mbeckham_2-1609730904249.png

The seconds/milliseconds    59.623  has rounded up, causing the minutes also to be rounded up.

 

How can I get the hours:minutes without the rounding?

 

Thanks

Mark

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
AlexKaras
Community Hero

Re: DateTime milliseconds rounding

Hi,

 

Consider .GetHours() and .GetMinutes() methods of aqDateTime object to get just hours and minutes and combine obtained values with the date and format as required.

Or convert the value obtained from the database to string and get a substring excluding everything after minutes.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

4 REPLIES 4
Marsha_R
Community Hero

Re: DateTime milliseconds rounding

I would convert it with this format  "%d/%m/%Y %H:%M%S" and then take a substring of the result with 

aqString.Substring(MyTimeString,0,15)

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqstring/substring.html

 

(I guessed at the 15 parameter, it's supposed to be the last character that you want out of the old string.  You many need to change that one.)

mbeckham
New Contributor

Re: DateTime milliseconds rounding

Hi Marsha,

I modified the code:

dateActioned = aqConvert.DateTimeToFormatStr(Qry3.FieldByName("ActionDateTime").Value, "%d/%m/%Y %H:%M%S");
Log.Message("dateActioned: " + dateActioned );

 

dateActioned: 26/11/2020 10:5800

 

As you can see the rounding has occurred during the format ( should be 10:5759 ) so the milliseconds ( 623) has caused the seconds to round up and then the minutes to round up also.

If there was a format code for the milliseconds portion of the datetime then I think there could be a viable solution using the substring to truncate them from the string.

AlexKaras
Community Hero

Re: DateTime milliseconds rounding

Hi,

 

Consider .GetHours() and .GetMinutes() methods of aqDateTime object to get just hours and minutes and combine obtained values with the date and format as required.

Or convert the value obtained from the database to string and get a substring excluding everything after minutes.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

sonya_m
Community Manager

Re: DateTime milliseconds rounding

Thank you for involving, Marsha and Alex!

 

@mbeckham did the advice help?


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors