cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
hcarr01
Level VI

sum date + month

Bonjour à tous,

 

J'aimerais faire une somme entre 2 colonnes (date et mois).

Voici un exemple ci-dessous :

 

hcarr01_0-1715781358755.png

Comment je pourrais créer une nouvelle colonne qui aurait pour résultat la somme des deux colonnes et donnerait : "02/09/2024".

La colonne date est en format date j/m/a et la colonne time est en format "mois" avec la personnalisation des formats.

 

Merci pour votre réponse.

 

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: sum date + month

The formula is

If( Month( :date ) + Num( :"time (month)"n ) <= 12,
Date MDY( Month( :date ) + Num( :"time (month)"n ), Day( :date ), Year( :date ) ),
Date MDY( (Month( :date ) + Num( :"time (month)"n )) - 12, Day( :date ), Year( :date ) + 1 )
)

txnelson_0-1715782087434.png

 

Jim

View solution in original post

jthi
Super User

Re: sum date + month

You can try using Date Increment() , but you might have to modify your month value (it seems to be character in your case, so use Num() to convert it in a formula). 

 

Names Default To Here(1);

dt = New Table("TEST (4)",
	Add Rows(1),
	Compress File When Saved(1),
	New Column("time", Numeric, Continuous, Set Values([4]), ),
	New Column("date", Numeric, "Continuous", Format("d/m/y", 12), Input Format("d/m/y"), Set Values([3797452800]), )
);

dt << New Column("a", numeric, continuous, Format("d/m/y", 12), Formula(Date Increment(:date, "month", :time, "actual")));

It might also be important to check how your solution works in possible corner cases (Date Increment(31Jan2024, "month", 1, "actual"))

 

-Jarmo

View solution in original post

6 REPLIES 6
txnelson
Super User

Re: sum date + month

The formula is

If( Month( :date ) + Num( :"time (month)"n ) <= 12,
Date MDY( Month( :date ) + Num( :"time (month)"n ), Day( :date ), Year( :date ) ),
Date MDY( (Month( :date ) + Num( :"time (month)"n )) - 12, Day( :date ), Year( :date ) + 1 )
)

txnelson_0-1715782087434.png

 

Jim

Re: sum date + month

There is no "month" function, likely because months have varying lengths. So I took a brute force approach to create a formula, but I believe it will work. Look at the New Date column in this file. But @txnelson 's approach is MUCH better! I had forgotten about the Date MDY function!

 

Dan Obermiller
jthi
Super User

Re: sum date + month

You can try using Date Increment() , but you might have to modify your month value (it seems to be character in your case, so use Num() to convert it in a formula). 

 

Names Default To Here(1);

dt = New Table("TEST (4)",
	Add Rows(1),
	Compress File When Saved(1),
	New Column("time", Numeric, Continuous, Set Values([4]), ),
	New Column("date", Numeric, "Continuous", Format("d/m/y", 12), Input Format("d/m/y"), Set Values([3797452800]), )
);

dt << New Column("a", numeric, continuous, Format("d/m/y", 12), Formula(Date Increment(:date, "month", :time, "actual")));

It might also be important to check how your solution works in possible corner cases (Date Increment(31Jan2024, "month", 1, "actual"))

 

-Jarmo
hcarr01
Level VI

Re: sum date + month

Bonjour,

 

Votre réponse fonctionne pour ajouter les mois. Mais lorsque la somme de la date + le mois dépasse l'année en cours, on obtient un problème (pas de résultat ou l'année ne devient pas l'année +1) :

 

hcarr01_0-1716889400364.png

 

Ici, le résultat de la colonne "somme" devrait être : 02/05/2025

 

Comment peut-on contourner ce problème ?

Merci pour votre réponse.

 

jthi
Super User

Re: sum date + month

Did you try with the solution I provided?

-Jarmo
hcarr01
Level VI

Re: sum date + month

yes it works correctly !