Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
11
Erster Beitrag:
vor 3 Monaten, 3 Wochen
Letzter Beitrag:
vor 3 Monaten, 2 Wochen
Beteiligte Autoren:
Yogi Yang, Fabrice Harari, Piet van Zanten, Gianni Spano, Allard

[WD20] - How to extract Month names from a given date range

Startbeitrag von Yogi Yang am 30.01.2018 14: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

Antworten:

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

von Fabrice Harari - am 30.01.2018 14:26
Hello Yogi

Take a look at: MonthInAlpha function

https://doc.windev.com/?1000019907&name=monthnumberinalpha_function

HTH

Gianni

von Gianni Spano - am 30.01.2018 14:27
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

von Yogi Yang - am 30.01.2018 14:47
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.

von Fabrice Harari - am 30.01.2018 18:54
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

von Yogi Yang - am 05.02.2018 08:02
just do ..month+=1 all the time, the year will be incremented automatically if needed...

von Fabrice Harari - am 05.02.2018 11:34
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

von Yogi Yang - am 05.02.2018 14:46
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

von Allard - am 06.02.2018 07:22
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

von Fabrice Harari - am 06.02.2018 14:40
Hi Yogi,

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

Kind regards,
Piet

von Piet van Zanten - am 06.02.2018 19:38
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.