Answer the question
In order to leave comments, you need to log in
How to display date from timestamp in Russian?
Good evening.
There is a table that stores data about air travel and related tables that store data about countries and cities.
The task is the following.
The user enters a search query about flights in a certain period of time. Gets the result of a search, such as flights between February 2 and February 15 to Bangkok City. Under the search results, you need to display links that will display information about flights to this city in other months (existing).
Example:
"Bangkok in February", "Bangkok in March", "Bangkok in April" ....... "Bangkok in December"
Flight dates are stored in a timestamp. To pull the name of the month from the timestamp used 'FROM_UNIXTIME(flights.date_end, \'%M\'). This is to get unique titles, without repetition.
Here is the request
if(($model = self::find()->select(['FROM_UNIXTIME(flights.date_end, \'%M\') as month', 'flights.city_end_id', 'cities.city', 'cities.description'])
->distinct()
->leftJoin('cities', 'cities.id=flights.city_end_id')
->where(['city_end_id' => $id])
->andWhere(['>=', 'date_end', mktime(0,0,0,date('m'),date('d'),date('Y'))])
->asArray()
->all()) !== null){
return $model;
}
else{
return false;
}
if(($model = self::find()->select(['FROM_UNIXTIME(flights.date_end, \'%Y-%m\') as month', 'flights.city_end_id', 'cities.city', 'cities.description'])
->distinct()
->leftJoin('cities', 'cities.id=flights.city_end_id')
->where(['city_end_id' => $id])
->andWhere(['>=', 'date_end', mktime(0,0,0,date('m'),date('d'),date('Y'))])
->asArray()
->all()) !== null){
return $model;
}
else{
return false;
}
// И перевод на русский, при условии, что formatter правильно настроен
echo Yii::$app->formatter->format($model->month, ['date', 'MMMM']);
Answer the question
In order to leave comments, you need to log in
I don't know how much advice will help (I don't practice PHP myself), but it seems to me that it's better to use date generation on the client using JS ... momentjs.com/docs It's easier to do cross-language output.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question