Convert Month from Name to Number

convert month from name to number

Yes,

$date = 'July 25 2010';
echo date('d/m/Y', strtotime($date));

The m formats the month to its numerical representation there.

Convert month names to numbers in r

You can use match() with the built-in variable month.name.

match(months, month.name)
[1] 3 4 5 6 7 8 9

Or convert your months variable to a factor and then an integer:

as.integer(factor(months, levels = month.name))

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

Easy way to convert the month name into month number in php

Try this :

<?php
$date = date_parse('March');
echo($date['month']);
?>

May this will help you :)

How to map month name to month number and vice versa?

Create a reverse dictionary using the calendar module (which, like any module, you will need to import):

{month: index for index, month in enumerate(calendar.month_abbr) if month}

In Python versions before 2.7, due to dict comprehension syntax not being supported in the language, you would have to do

dict((month, index) for index, month in enumerate(calendar.month_abbr) if month)

Convert Month Name into Number With Different Languages?

If you can integrate the external class dt try this:

$visit_date = "7 Dezembro, 2019";

dt::setDefaultLanguage('pt');
$dt = dt::create($visit_date);

echo $dt->format('Y-m-d');//2019-12-07

Internally, the class creates a translation table for every month when setting the language. The IntlDateFormatter class is used for this.

Note: The IntlDateFormatter class works independently of the server's local settings.

Converting month name to month number in SQL Server

Just another option is to try_convert() into a date

Note: the format() is optional

Example

Declare @YourTable Table ([Period_Name] varchar(50))  Insert Into @YourTable Values 
('Jan-19')
,('Feb-19')

Select *
,NewVal = format(try_convert(date,'01-'+Period_Name),'MM')
from @YourTable

Returns

Period_Name NewVal
Jan-19 01
Feb-19 02


Related Topics



Leave a reply



Submit