473,320 Members | 1,948 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,320 software developers and data experts.

count hours within months

wz
Hi,
I'm new to access sql, and have a simple question.
I have a date field, named log_dt, and I'm trying to count how many
hours each record is from starting time of it's own month. But the 5
in #5/1/2003# need to be changed according to the record, not hard
coded. How can I achieve that? Is there a date function that I can
create a date with specified month and day?

SELECT
DateDiff("h",#5/1/2003#,[LOCAL DATA].[LOG_DT]) AS hours,
DateDiff("m",#1/1/2003#,[LOCAL DATA].[LOG_DT])+1 AS months,
FROM [LOCAL DATA]
thanks a lot,

Wei
Nov 13 '05 #1
1 2698
Sounds as though you want the DateSerial function.

Assuming you're trying to get the first for each month of Log_Dt, you'd need
something like:

SELECT
DateDiff("h",DateSerial(Year([LOG_DT], Month([LOG_DT]), 1),[LOG_DT]) AS
hours,
DateDiff("m",DateSerial(Year([LOG_DT], 1, 1),[LOG_DT])+1 AS months,
FROM [LOCAL DATA]
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"wz" <zw****@gmail.com> wrote in message
news:89**************************@posting.google.c om...
Hi,
I'm new to access sql, and have a simple question.
I have a date field, named log_dt, and I'm trying to count how many
hours each record is from starting time of it's own month. But the 5
in #5/1/2003# need to be changed according to the record, not hard
coded. How can I achieve that? Is there a date function that I can
create a date with specified month and day?

SELECT
DateDiff("h",#5/1/2003#,[LOCAL DATA].[LOG_DT]) AS hours,
DateDiff("m",#1/1/2003#,[LOCAL DATA].[LOG_DT])+1 AS months,
FROM [LOCAL DATA]
thanks a lot,

Wei

Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joseph Santaniello | last post by:
Hello all, I have a table with among other things a timestamp field. To get the count of records per hour I do: select count(*) as c, date_trunc('hour', timestmp) as h from mytable
8
by: Michael | last post by:
I have this script that works the way I want except for one thing... Once it hits zero it starts to count up and looks like this: -1:0-1:0-1:0-18 with the last number counting up. Can anyone...
4
by: m_houllier | last post by:
STUDENT TABLE StudentReference Student Name etc ATTENDANCE TABLE AttendanceID CourseID StudentReference
7
by: Stu | last post by:
Is there a simple function call within "C" that I can use to convert number of seconds (keep in mind this may be a type longlong and has to work on UNIX and NT) into Days, months, Hours, Minutes...
20
by: none | last post by:
I have managed to get the below script *almost* working. However, it still has a problem calculating the number of months. The date I am trying to calculate from is Oct 15, 1994. With the correct...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
2
by: jonathan184 | last post by:
Hi I am having a problme where the results of the sql count is not matching the results of the perl script sql count. The script was working fine up till Wed last week and after that the results...
4
by: Sjef ten Koppel | last post by:
Hi, I've a small problem. I have a table in which one column is date. I want to count the records for statiscs in a temptable grouped by months lets say 12 months back. e.g. month 1 counts 164...
3
missshaikh
by: missshaikh | last post by:
Hi all, i need the count down timer when button click the timer start and count down work on ASP.net :( i have one timer which is on JavaScript that run page onload . but i need the Button...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.