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
Query Records Through Its Belongs_To Relation in Rails
How to Execute Custom Actions After Successful Sign in with Devise
Setting Path for Whenever in Cron So It Can Find Ruby
Generating an Instagram- or Youtube-Like Unguessable String Id in Ruby/Activerecord
How to Format This International Phone Number in Rails
How to Access Attributes Using Nokogiri
How to Customize Rails Activerecord Validation Error Message to Show Attribute Value
How to Use Gems Not in a Gemfile When Working with Bundler
Why Doesn't "Rails S" Work from the App Directory
Rails Carrierwave Base64 Image Upload
Rails - Local Variables Versus Instance Variables
Ruby, Remove Last N Characters from a String
How to Get Last N Records with Activerecord
Replace Words in a String - Ruby
Removing a Model in Rails (Reverse of "Rails G Model Title...")