PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → [WD20] - How to extract Month names from a given date range
[WD20] - How to extract Month names from a given date range
Iniciado por guest, 30,ene. 2018 15:03 - 10 respuestas
Publicado el 30,enero 2018 - 15:03
Hello,

I want to extract Month names from a given date range (that is between start date and end date as selected by user)

For example if user selects start date as: 01/01/2018 and end date as: 20/10/2018 I want to extract and show month names: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sept, Oct

TIA
Publicado el 30,enero 2018 - 15:26
Hi

use a date variable for each date
make a loop
inside the loop, compare the begin and end
if you are still in in the interval, extract the month (dateToString with a custom format)
add 1 to the month property of your begin date variable
end loop

Best regards
Publicado el 30,enero 2018 - 15:27
Hello Yogi

Take a look at: MonthInAlpha function

https://doc.windev.com/…

HTH

Gianni
Publicado el 30,enero 2018 - 15:47
Hello,

Fabrice thanks for your suggestions.

Currently I am using a loop to iterate between all the days between given date range as suggested by Fabrice but unfortunately at times when the user gives very wide date range for more than 4 years it takes quite some time so I posted here for a better and solution which is quicker and more efficient.

TIA
Publicado el 30,enero 2018 - 19:54
Hi again

>>>Currently I am using a loop to iterate between all the days between given date range as suggested by Fabrice but unfortunately at times when the user gives very wide date range for more than 4 years it takes quite some time so I posted here for a better and solution which is quicker and more efficient.<<<

Well, MY solution is to iterate on the MONTHS, not on the days, as stated in the previous message... So it's going to be about 30 times faster...
Publicado el 05,febrero 2018 - 09:02
Fabrice,

Sorry for delay in my reply. And thanks for the tip.

Here is the final code that I am using to get Months name between given Dates using your suggested 30x faster Month technique :) :
dEndDate is Date = DateSys() dCurrentDate is Date = DateSys() sMonthName is string dEndDate = gdEndDate dCurrentDate = gdStartDate WHILE dCurrentDate < dYearEndDate sMonthName = DateToMonthInAlpha(dCurrentDate) + " " + dCurrentDate..Year IF dCurrentDate..Month = 12 THEN dCurrentDate..Month = 1 dCurrentDate..Year = dCurrentDate..Year + 1 ELSE dCurrentDate..Month = dCurrentDate..Month + 1 END END
TIA
Publicado el 05,febrero 2018 - 12:34
just do ..month+=1 all the time, the year will be incremented automatically if needed...
Publicado el 05,febrero 2018 - 15:46
Quote
Fabrice Harari

just do ..month+=1 all the time, the year will be incremented automatically if needed...
Unfortunately that is not happening in my case. I tied your suggestion but got run time error so I changed the code.

TIA
Publicado el 06,febrero 2018 - 08:22
HI
example :

Fiel with a datefield set to a var :

monthname is string

monthname = DateToMonthInAlpha(Filename.Date)

So on the range start at beginning or at end. Do a loop end when name chnages add it to the list of month names

regards
Publicado el 06,febrero 2018 - 15:40
Quote
Yogi Yang


Quote
Fabrice Harari

just do ..month+=1 all the time, the year will be incremented automatically if needed...

Unfortunately that is not happening in my case. I tied your suggestion but got run time error so I changed the code.



TIA

Then your code was incorrect... pOst it here if you want help

Best regards
Publicado el 06,febrero 2018 - 20:38
Hi Yogi,

Before using any date functions it's good practice to test for DateValid() first.

Kind regards,
Piet