Name of This Month (Date.Today.Month as Name)

Name of this month (Date.today.month as name)

Date::MONTHNAMES[Date.today.month] would give you "January". (You may need to require 'date' first).

Get month name from Date

Shorter version:





const monthNames = ["January", "February", "March", "April", "May", "June",

"July", "August", "September", "October", "November", "December"

];


const d = new Date();

document.write("The current month is " + monthNames[d.getMonth()]);

How can I get month name from month number

Use format string.

(Time.now + 1.month).strftime("%B")
# => "October"

python/pandas: convert month int to month name

You can do this efficiently with combining calendar.month_abbr and df[col].apply()

import calendar
df['Month'] = df['Month'].apply(lambda x: calendar.month_abbr[x])

Get month name from number

Calendar API

From that you can see that calendar.month_name[3] would return March, and the array index of 0 is the empty string, so there's no need to worry about zero-indexing either.

How can I get Month Name from Calendar?


String getMonthForInt(int num) {
String month = "wrong";
DateFormatSymbols dfs = new DateFormatSymbols();
String[] months = dfs.getMonths();
if (num >= 0 && num <= 11) {
month = months[num];
}
return month;
}

Easiest way to convert month name to month number in JS ? (Jan = 01)

Just for fun I did this:

function getMonthFromString(mon){
return new Date(Date.parse(mon +" 1, 2012")).getMonth()+1
}

Bonus: it also supports full month names :-D
Or the new improved version that simply returns -1 - change it to throw the exception if you want (instead of returning -1):

function getMonthFromString(mon){

var d = Date.parse(mon + "1, 2012");
if(!isNaN(d)){
return new Date(d).getMonth() + 1;
}
return -1;
}

Sry for all the edits - getting ahead of myself

Given start date get all the months name until current month?

here you go , hope this work

$start    = new DateTime('2019-01-01');

$end = new DateTime('2020-03-02');

$interval = DateInterval::createFromDateString('1 month');
$period = new DatePeriod($start, $interval, $end);

foreach ($period as $dt) {
echo $dt->format("F Y") . "<br>\n";
}


Related Topics



Leave a reply



Submit