473,809 Members | 2,758 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

display diffdate in years and months

1 New Member
Greetings to everyone,

I have the following code to find a date at the first of the month following a time period. Now I need to find the difference in years and months from this new date to sysdate(). I have tried to use datediff() to no avail on the new date and even if I got it to work it would only give the days which could be broken down into years but I don't think I could get an accurate picture of months. Tried date_sub but couldn't get it to work. Any ideas out there? All and any help would be greatly appreciated.
select ename,
Expand|Select|Wrap|Line Numbers
  1.   DATE_FORMAT(HireDate,'%d-%b-%y') 'Hire Date',
  2.   DATE_FORMAT(DATE_ADD(DATE_ADD(HireDate, interval 3 month),interval
  3.   (case date_format(date_add(hiredate, '%y-%m-01') + interval 1 month),
  4.   (date_format(date_add(hiredate, interval 3 month)),end), '%W, the %D of %M, %Y') 'insurance'
  5. from employee;
Oct 25 '07 #1
1 3697
r035198x
13,262 MVP
Greetings to everyone,

I have the following code to find a date at the first of the month following a time period. Now I need to find the difference in years and months from this new date to sysdate(). I have tried to use datediff() to no avail on the new date and even if I got it to work it would only give the days which could be broken down into years but I don't think I could get an accurate picture of months. Tried date_sub but couldn't get it to work. Any ideas out there? All and any help would be greatly appreciated.
select ename,
DATE_FORMAT(Hir eDate,'%d-%b-%y') 'Hire Date',
DATE_FORMAT(DAT E_ADD(DATE_ADD( HireDate, interval 3 month),interval
(case date_format(dat e_add(hiredate, '%y-%m-01') + interval 1 month),
(date_format(da te_add(hiredate , interval 3 month)),end), '%W, the %D of %M, %Y') 'insurance'
from employee;
See the refmanual for date functions. Also read the examples posted in there and comments added by other MySQL users as well.
Oct 25 '07 #2

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

Similar topics

7
12815
by: Bambero | last post by:
Hello all Problem like in subject. There is no problem when I want to count days between two dates. Problem is when I want to count years becouse of leap years. For ex. between 2002-11-19 2003-11-19
6
27999
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
5
8840
by: Juan | last post by:
Hi everyone, is there a function that calculates the exact amount of Years, Months, and Days between two days? TimeDiff is not good enough, since it calculates, for example: Date 1: Dec. 31st 2003 Date 2: Jan 1st 2004
9
1659
by: Jack | last post by:
To whom may concern: In Asp.Net Calender control, how to display 5 lines if there are only 5 lines in one month? Now there are 6 lines even that I don't show the data in other months. Thanks in advance!
1
1264
by: Olaf Rabbachin | last post by:
Hi folks, I have a table in an Access-DB that has a date-field (date + time). I'd like to use a DataSet + DataGrid to achieve a grouped/hierarchical display where the user would work his/her way from years to months therein (rows with items only) and finally the data-rows themselves. My first idea is to setup a DataSet containing virtual tables, but I'm wondering as to how I could split up the date from the database into date & time...
37
2299
by: Gregc. | last post by:
G'day I'm trying to work out the number of years since 1970, here is my code: include <stdio.h> #include <time.h> const int SEC_IN_MIN = 60; const int SEC_IN_HOUR = SEC_IN_MIN * 60;
23
14070
by: thebjorn | last post by:
For the purpose of finding someone's age I was looking for a way to find how the difference in years between two dates, so I could do something like: age = (date.today() - born).year but that didn't work (the timedelta class doesn't have a year accessor). I looked in the docs and the cookbook, but I couldn't find anything, so
4
6913
by: MCLR | last post by:
Good day to all: I found your website a couple of days ago as I was searching for resources that can help within my particular problem in writing a script for an Access Query. The issue is to calculate a month and year situation. What I need is to create a query that will pull up how many months and years an employee has been working at a (now) date. For example: Employee A as been employed 2 years and 4 months and Employee B as been...
2
4843
by: ichew | last post by:
I have two dates - Date Joined and Actual Last Day. How do I find the YIS in for format of Years and Month from these two dates. Eg, Date Joined: 28/06/1971 and Actual Last Day: 24/01/2007, then the YIS should shows: 35 yrs 6 mth.
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10635
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...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7653
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
6881
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
5550
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...
1
4332
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
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3013
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.