473,786 Members | 2,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Determining number of days between today and value in datetime field without DATEDIFF?

Hi All,

I'm trying to determine the number of days between today and the value
in a datetime field in a table.
It appears my version of MySQL doesn't have DATEDIFF available, so I'm
wondering if there's another method to achieve the same result as:

SELECT DATEDIFF(CURDAT E(),`mydate`) AS numdays FROM tblArticles WHERE
artid = 10

Any help appreciated!

Much warmth,

planetthoughtfu l
---
"Lost in thought"
http://www.planetthoughtful.org

May 10 '06 #1
3 2902

<pl************ **@gmail.com> wrote in message
news:11******** **************@ u72g2000cwu.goo glegroups.com.. .
Hi All,

I'm trying to determine the number of days between today and the value
in a datetime field in a table.
It appears my version of MySQL doesn't have DATEDIFF available, so I'm
wondering if there's another method to achieve the same result as:

SELECT DATEDIFF(CURDAT E(),`mydate`) AS numdays FROM tblArticles WHERE
artid = 10

Any help appreciated!


Is the UNIX_TIMESTAMP( ) function available?
Try "SELECT UNIX_TIMESTAMP( NOW())" and see.

UNIX_TIMESTAMP( ) returns the number of seconds between the date/time
argument and some base time. The base time will be different Unix/Linux or
Windows but you really don't care what it is. Because when you subtract
UNIX_TIMESTAMP( NOW()) - UNIX_TIMESTAMP( datetimefield)
you will always get the number of seconds that has elapsed between this
moment and your {datetimefield} .

Now you only need to convert seconds to days.

SELECT
(UNIX_TIMESTAMP (NOW())-UNIX_TIMESTAMP( datetimefield)) / (60 * 60 * 24) As
numdays

Returns the value as a floating point value for numdays.
If you need to see it as an integer, enclose it all inside the TRUNCATE() or
ROUND() functions depending upon how you like your integers ;-)

Thomas Bartkus
May 10 '06 #2
Thomas Bartkus wrote:
Now you only need to convert seconds to days.


FWIW, there's also a TO_DAYS() function in MySQL, so you don't even have
to do the conversion of seconds to days.

See http://dev.mysql.com/doc/refman/4.1/...functions.html

Regards,
Bill K.
May 10 '06 #3
Hi Thomas,

Thanks for this - very helpful!

Much warmth,

planetthoughtfu l
---
"lost in thought"
http://www.planetthoughtful.org1

May 10 '06 #4

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

Similar topics

2
1657
by: PK9 | last post by:
I have a loop where I need to calculate a series of dates based on: 1) a start date (DateTime variable) 2) a number of days (integer variable) I need to take the start date, then add the number of days to it, and come up with the next date. eg. - DateTime variable might equal 01/02/2005 - My integer for "Number of Days" is 10
7
60508
by: Vinnie Davidson | last post by:
Hello! I'm trying to get all records from my SQL Server Database with "DeadlineDate" = today (not today - 24 hours). All records has a field called "DeadlineDate", and the date is stored in this field like this: 13.08.2005 07:00:00 I dont care about the hours (Ex: 07:00:00), just the date (ex: 13.08.2005). This is the SQL I have made, it gets all the record with the date = today -
2
14157
by: Rimdur | last post by:
I am trying to get a difference between two dates calculated in a query. I have Sales_Date as the first one, and Date() as the second one. How would I put the difference of these two days into a field? I have tried something like this: DateDiff("d", Now(), Sales_Date) Then I get an error like this: "Datatype mismatch in criteria expression". Sales_Date is formatted as a Date format. -Thanks for all help
6
2055
by: HateSpam | last post by:
I am trying to write a function that determines how many hours there are until a certain date/time that depends on what today's date/time is. Basically, how many hours from now until the next time that it is 8am on Monday. I've found the dateadd, hour, and weekday functions, but I can't seem to get it straight in my head how to use them in this case.
1
2293
by: rock72 | last post by:
I am developing a application using this fields as required by the company. 1. Date Login 2. Time IN 3. Time OUT My question is how to produce the number of days with 1 entry of Date is the entry ?
6
27994
by: carl.barrett | last post by:
Hi, I have a continuous form based on a query ( I will also be creating a report based on the same query). There are 2 fields: Date Obtained and Date Of Expiry I want a further 3 columns to the right of these 2 fields to show the
2
4556
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was set to...it is set to false. Can someone show me what I am doing wrong and tell me the correct way? Thank you. In the page load event, I am doing the following:
4
1649
realin
by: realin | last post by:
hi guys.. I have made a function which counts the numbers of days or hours or minutes from the current datetime to the give datetime.. but i am confused while displaying number of days along with number of hours.. rest all works fine(I Suppose). here is the code : function day_counter($date,$msg){ $today=time(); $day_to_count=strtotime($date);
1
7213
by: bharathreddy | last post by:
This article will explain how we can get the count of weekdays in between two dates. This will be usefull if we want to count the number of working days between two dates. Example: ------------- USE GO --This function is used to count the number of weekdays between -- two dates. create function udf_Weekdays(@Weekday,@BeginDate datetime,@EndDate datetime) returns integer
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6748
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.