473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to calculate time difference between datetime and only time

Hi sir, I want to calculate time in a proper format (hours, minute and second).
My first field type is datetime directly fetch from database and second one is fixed it's 08:30:00.
Feb 11 '17 #1
1 1953
tsp314
1
Hi mayurm38.

A date/time/datetime is a fractional number.
The whole number part is the day number where jan 1 1900 is day number 1.
The fractional part is the time. Since a day has 24 hours the value of 1 hour is 1/24 or 0.0416666667. 6 hours is 0.25.

So in order to calculate the time difference only, we have to get rid of the date part.

The next piece of code is one way of doing that.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Sub timeDifference()
  5.    Dim dt   As Date  'date and time
  6.    Dim tm   As Date  'time only
  7.    Dim dif  As Double
  8.  
  9.    dt = #2/20/2017 2:30:00 PM#
  10.    tm = #8:30:00 AM#
  11.  
  12.    dif = dt - Int(dt) - tm 'remove the date(whole number) part from dt
  13.  
  14.    'next line prints
  15.    ' 0,249999999997575          06:00:00
  16.  
  17.    Debug.Print dif, Format(dif, "hh:mm:ss")
  18. End Sub
  19.  
Feb 22 '17 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Richard | last post by:
Hi, Is there any way to get the time difference between Central(US) and GMT in vb.net. I'll appreciate your help/suggestion. Thanks RC
4
by: Vivek Sharma | last post by:
Hi, I need to calculate the time difference between today 2pm and tomorrow 2 am. How do I calculate? Thanks Vivek
3
by: bbawa1 | last post by:
Hi, I have a table which has a field ItemsReceived of type datetime. I have a grid view which has two columns. In first column i have to show the data from field ItemsReceived and in second...
2
by: cmrhema | last post by:
Hello I have a table GPSDATA which consists of VehicleNo,Speed,CurrentDate,slno,status This data gets updated every minute.And every minute the slno(serial no) will be incremented...
2
by: idealfellow | last post by:
I am using the following to get the time: puts Time.now --> starting of my script <MY CODE> puts Time.now --> end of my script I want to get the Time difference between two Time.now...
3
by: Steve | last post by:
I am trying to calculate elapsed travel times for flights. My plan is to enter the local departure time, the departure city and the local arrival time and city. These times would be standardised...
15
by: student4lifer | last post by:
Hello, I have 2 time fields dynamically generated in format "m/d/y H:m". Could someone show me a good function to calculate the time interval difference in minutes? I played with strtotime() but...
5
by: SamarKhanimcq | last post by:
Ive set 2 coulumns of my table as "Time In" and "Time Out". I want Access to calculate the time difference automatically and then i want to run a query that pulls out all records in which the time...
2
by: bluemoon9 | last post by:
On my form, I have 3 fields: StartTime (milliary time 00:00), EndTime (milliary time 00:00) and Mintues (number). I would like to place a control calcuation statement in the Field Properties/Control...
3
by: Gareth Jones | last post by:
Hi all, I have a database that records issues and incidents based on different priorities. I am trying to write a query to show the time difference since the last incident depending on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.