Laravel - Getting Current Month and Year only
I am new to Laravel I'm just learning new things, but as for my project. I need to get the current month and year for today. How can I do it? for what I have now is a label and I want to put the current month and year on the label. Thank you
Here is my LABEL
{{Form::label('title', 'Title')}}
php laravel datetime
add a comment |
I am new to Laravel I'm just learning new things, but as for my project. I need to get the current month and year for today. How can I do it? for what I have now is a label and I want to put the current month and year on the label. Thank you
Here is my LABEL
{{Form::label('title', 'Title')}}
php laravel datetime
How about using jQuery instead of Laravel for month and year?
– Bonish Koirala
Nov 20 '18 at 5:07
How is it gonna work? can you show me a sample code? thank you
– user10665294
Nov 20 '18 at 5:09
add a comment |
I am new to Laravel I'm just learning new things, but as for my project. I need to get the current month and year for today. How can I do it? for what I have now is a label and I want to put the current month and year on the label. Thank you
Here is my LABEL
{{Form::label('title', 'Title')}}
php laravel datetime
I am new to Laravel I'm just learning new things, but as for my project. I need to get the current month and year for today. How can I do it? for what I have now is a label and I want to put the current month and year on the label. Thank you
Here is my LABEL
{{Form::label('title', 'Title')}}
php laravel datetime
php laravel datetime
asked Nov 20 '18 at 5:06
user10665294
How about using jQuery instead of Laravel for month and year?
– Bonish Koirala
Nov 20 '18 at 5:07
How is it gonna work? can you show me a sample code? thank you
– user10665294
Nov 20 '18 at 5:09
add a comment |
How about using jQuery instead of Laravel for month and year?
– Bonish Koirala
Nov 20 '18 at 5:07
How is it gonna work? can you show me a sample code? thank you
– user10665294
Nov 20 '18 at 5:09
How about using jQuery instead of Laravel for month and year?
– Bonish Koirala
Nov 20 '18 at 5:07
How about using jQuery instead of Laravel for month and year?
– Bonish Koirala
Nov 20 '18 at 5:07
How is it gonna work? can you show me a sample code? thank you
– user10665294
Nov 20 '18 at 5:09
How is it gonna work? can you show me a sample code? thank you
– user10665294
Nov 20 '18 at 5:09
add a comment |
4 Answers
4
active
oldest
votes
If you want to always display the current day's month and year, you can use PHP's built-in date function. For example, the below will give you a label November 2018.
{{Form::label('title', date('F Y') )}}
See PHP Documentation on the date function
If you want more powerful manipulation, use Carbon.
2
date('F Y')would work.
– Sougata Bose
Nov 20 '18 at 5:18
Hey dude, can I save it to database as STRING ?
– user10665294
Nov 20 '18 at 5:24
Of course,date()returns a string.
– hktang
Nov 20 '18 at 5:25
On the other hand? Can I also save it as DATE?
– user10665294
Nov 20 '18 at 5:30
Since you are using Laravel, you might want to check this page for some handy methods of saving dates. laravel.com/docs/5.7/eloquent-mutators#date-mutators. Usingdate, it's just about formatting your date into the default format: w3schools.com/sql/sql_dates.asp
– hktang
Nov 20 '18 at 5:33
|
show 2 more comments
You can use the Carbon library which is available out of the box with Laravel:
{{ Form::label('title', CarbonCarbon::now()->format('M, Y') }}
You can format using native PHP DateTime Format
Update:
As @Josh mentioned, you can also use the laravel helper now()
The now function creates a new IlluminateSupportCarbon instance for the current time
{{ Form::label('title', now()->format('M, Y') }}
Hey dude, I thought it was gonna work but error was found how to solve this one? Class 'Carbon' not found
– user10665294
Nov 20 '18 at 5:13
@SummerWinter add use CarbonCarbon to the top of your file above your class declaration
– Josh
Nov 20 '18 at 5:15
1
Or you can just change it to now()->format('M, Y')
– Josh
Nov 20 '18 at 5:15
add a comment |
You can also try this.
{{ Form::label('title', CarbonCarbon::now()->format('F Y') }}
add a comment |
Laravel come with a prebuilt component to manage Date, and it's know under the name Carbon it have many method to access and modifie DateTime php object. To access the month and year of the current day you can access the property month and year directly on the Carbon Object
$today = Carbon::now();
$today->month; // retrieve the month
$today->year; // retrieve the year of the date
In you Controller you can pas the $today object to the method use to render the related view with purpose to have access to that object on a get value of attribute that you want to show in the label field
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386547%2flaravel-getting-current-month-and-year-only%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you want to always display the current day's month and year, you can use PHP's built-in date function. For example, the below will give you a label November 2018.
{{Form::label('title', date('F Y') )}}
See PHP Documentation on the date function
If you want more powerful manipulation, use Carbon.
2
date('F Y')would work.
– Sougata Bose
Nov 20 '18 at 5:18
Hey dude, can I save it to database as STRING ?
– user10665294
Nov 20 '18 at 5:24
Of course,date()returns a string.
– hktang
Nov 20 '18 at 5:25
On the other hand? Can I also save it as DATE?
– user10665294
Nov 20 '18 at 5:30
Since you are using Laravel, you might want to check this page for some handy methods of saving dates. laravel.com/docs/5.7/eloquent-mutators#date-mutators. Usingdate, it's just about formatting your date into the default format: w3schools.com/sql/sql_dates.asp
– hktang
Nov 20 '18 at 5:33
|
show 2 more comments
If you want to always display the current day's month and year, you can use PHP's built-in date function. For example, the below will give you a label November 2018.
{{Form::label('title', date('F Y') )}}
See PHP Documentation on the date function
If you want more powerful manipulation, use Carbon.
2
date('F Y')would work.
– Sougata Bose
Nov 20 '18 at 5:18
Hey dude, can I save it to database as STRING ?
– user10665294
Nov 20 '18 at 5:24
Of course,date()returns a string.
– hktang
Nov 20 '18 at 5:25
On the other hand? Can I also save it as DATE?
– user10665294
Nov 20 '18 at 5:30
Since you are using Laravel, you might want to check this page for some handy methods of saving dates. laravel.com/docs/5.7/eloquent-mutators#date-mutators. Usingdate, it's just about formatting your date into the default format: w3schools.com/sql/sql_dates.asp
– hktang
Nov 20 '18 at 5:33
|
show 2 more comments
If you want to always display the current day's month and year, you can use PHP's built-in date function. For example, the below will give you a label November 2018.
{{Form::label('title', date('F Y') )}}
See PHP Documentation on the date function
If you want more powerful manipulation, use Carbon.
If you want to always display the current day's month and year, you can use PHP's built-in date function. For example, the below will give you a label November 2018.
{{Form::label('title', date('F Y') )}}
See PHP Documentation on the date function
If you want more powerful manipulation, use Carbon.
edited Nov 20 '18 at 5:18
answered Nov 20 '18 at 5:17
hktanghktang
9491429
9491429
2
date('F Y')would work.
– Sougata Bose
Nov 20 '18 at 5:18
Hey dude, can I save it to database as STRING ?
– user10665294
Nov 20 '18 at 5:24
Of course,date()returns a string.
– hktang
Nov 20 '18 at 5:25
On the other hand? Can I also save it as DATE?
– user10665294
Nov 20 '18 at 5:30
Since you are using Laravel, you might want to check this page for some handy methods of saving dates. laravel.com/docs/5.7/eloquent-mutators#date-mutators. Usingdate, it's just about formatting your date into the default format: w3schools.com/sql/sql_dates.asp
– hktang
Nov 20 '18 at 5:33
|
show 2 more comments
2
date('F Y')would work.
– Sougata Bose
Nov 20 '18 at 5:18
Hey dude, can I save it to database as STRING ?
– user10665294
Nov 20 '18 at 5:24
Of course,date()returns a string.
– hktang
Nov 20 '18 at 5:25
On the other hand? Can I also save it as DATE?
– user10665294
Nov 20 '18 at 5:30
Since you are using Laravel, you might want to check this page for some handy methods of saving dates. laravel.com/docs/5.7/eloquent-mutators#date-mutators. Usingdate, it's just about formatting your date into the default format: w3schools.com/sql/sql_dates.asp
– hktang
Nov 20 '18 at 5:33
2
2
date('F Y') would work.– Sougata Bose
Nov 20 '18 at 5:18
date('F Y') would work.– Sougata Bose
Nov 20 '18 at 5:18
Hey dude, can I save it to database as STRING ?
– user10665294
Nov 20 '18 at 5:24
Hey dude, can I save it to database as STRING ?
– user10665294
Nov 20 '18 at 5:24
Of course,
date() returns a string.– hktang
Nov 20 '18 at 5:25
Of course,
date() returns a string.– hktang
Nov 20 '18 at 5:25
On the other hand? Can I also save it as DATE?
– user10665294
Nov 20 '18 at 5:30
On the other hand? Can I also save it as DATE?
– user10665294
Nov 20 '18 at 5:30
Since you are using Laravel, you might want to check this page for some handy methods of saving dates. laravel.com/docs/5.7/eloquent-mutators#date-mutators. Using
date, it's just about formatting your date into the default format: w3schools.com/sql/sql_dates.asp– hktang
Nov 20 '18 at 5:33
Since you are using Laravel, you might want to check this page for some handy methods of saving dates. laravel.com/docs/5.7/eloquent-mutators#date-mutators. Using
date, it's just about formatting your date into the default format: w3schools.com/sql/sql_dates.asp– hktang
Nov 20 '18 at 5:33
|
show 2 more comments
You can use the Carbon library which is available out of the box with Laravel:
{{ Form::label('title', CarbonCarbon::now()->format('M, Y') }}
You can format using native PHP DateTime Format
Update:
As @Josh mentioned, you can also use the laravel helper now()
The now function creates a new IlluminateSupportCarbon instance for the current time
{{ Form::label('title', now()->format('M, Y') }}
Hey dude, I thought it was gonna work but error was found how to solve this one? Class 'Carbon' not found
– user10665294
Nov 20 '18 at 5:13
@SummerWinter add use CarbonCarbon to the top of your file above your class declaration
– Josh
Nov 20 '18 at 5:15
1
Or you can just change it to now()->format('M, Y')
– Josh
Nov 20 '18 at 5:15
add a comment |
You can use the Carbon library which is available out of the box with Laravel:
{{ Form::label('title', CarbonCarbon::now()->format('M, Y') }}
You can format using native PHP DateTime Format
Update:
As @Josh mentioned, you can also use the laravel helper now()
The now function creates a new IlluminateSupportCarbon instance for the current time
{{ Form::label('title', now()->format('M, Y') }}
Hey dude, I thought it was gonna work but error was found how to solve this one? Class 'Carbon' not found
– user10665294
Nov 20 '18 at 5:13
@SummerWinter add use CarbonCarbon to the top of your file above your class declaration
– Josh
Nov 20 '18 at 5:15
1
Or you can just change it to now()->format('M, Y')
– Josh
Nov 20 '18 at 5:15
add a comment |
You can use the Carbon library which is available out of the box with Laravel:
{{ Form::label('title', CarbonCarbon::now()->format('M, Y') }}
You can format using native PHP DateTime Format
Update:
As @Josh mentioned, you can also use the laravel helper now()
The now function creates a new IlluminateSupportCarbon instance for the current time
{{ Form::label('title', now()->format('M, Y') }}
You can use the Carbon library which is available out of the box with Laravel:
{{ Form::label('title', CarbonCarbon::now()->format('M, Y') }}
You can format using native PHP DateTime Format
Update:
As @Josh mentioned, you can also use the laravel helper now()
The now function creates a new IlluminateSupportCarbon instance for the current time
{{ Form::label('title', now()->format('M, Y') }}
edited Nov 20 '18 at 5:16
answered Nov 20 '18 at 5:11
Angad DubeyAngad Dubey
2,42221634
2,42221634
Hey dude, I thought it was gonna work but error was found how to solve this one? Class 'Carbon' not found
– user10665294
Nov 20 '18 at 5:13
@SummerWinter add use CarbonCarbon to the top of your file above your class declaration
– Josh
Nov 20 '18 at 5:15
1
Or you can just change it to now()->format('M, Y')
– Josh
Nov 20 '18 at 5:15
add a comment |
Hey dude, I thought it was gonna work but error was found how to solve this one? Class 'Carbon' not found
– user10665294
Nov 20 '18 at 5:13
@SummerWinter add use CarbonCarbon to the top of your file above your class declaration
– Josh
Nov 20 '18 at 5:15
1
Or you can just change it to now()->format('M, Y')
– Josh
Nov 20 '18 at 5:15
Hey dude, I thought it was gonna work but error was found how to solve this one? Class 'Carbon' not found
– user10665294
Nov 20 '18 at 5:13
Hey dude, I thought it was gonna work but error was found how to solve this one? Class 'Carbon' not found
– user10665294
Nov 20 '18 at 5:13
@SummerWinter add use CarbonCarbon to the top of your file above your class declaration
– Josh
Nov 20 '18 at 5:15
@SummerWinter add use CarbonCarbon to the top of your file above your class declaration
– Josh
Nov 20 '18 at 5:15
1
1
Or you can just change it to now()->format('M, Y')
– Josh
Nov 20 '18 at 5:15
Or you can just change it to now()->format('M, Y')
– Josh
Nov 20 '18 at 5:15
add a comment |
You can also try this.
{{ Form::label('title', CarbonCarbon::now()->format('F Y') }}
add a comment |
You can also try this.
{{ Form::label('title', CarbonCarbon::now()->format('F Y') }}
add a comment |
You can also try this.
{{ Form::label('title', CarbonCarbon::now()->format('F Y') }}
You can also try this.
{{ Form::label('title', CarbonCarbon::now()->format('F Y') }}
answered Nov 21 '18 at 4:36
Sheetal MehraSheetal Mehra
1624
1624
add a comment |
add a comment |
Laravel come with a prebuilt component to manage Date, and it's know under the name Carbon it have many method to access and modifie DateTime php object. To access the month and year of the current day you can access the property month and year directly on the Carbon Object
$today = Carbon::now();
$today->month; // retrieve the month
$today->year; // retrieve the year of the date
In you Controller you can pas the $today object to the method use to render the related view with purpose to have access to that object on a get value of attribute that you want to show in the label field
add a comment |
Laravel come with a prebuilt component to manage Date, and it's know under the name Carbon it have many method to access and modifie DateTime php object. To access the month and year of the current day you can access the property month and year directly on the Carbon Object
$today = Carbon::now();
$today->month; // retrieve the month
$today->year; // retrieve the year of the date
In you Controller you can pas the $today object to the method use to render the related view with purpose to have access to that object on a get value of attribute that you want to show in the label field
add a comment |
Laravel come with a prebuilt component to manage Date, and it's know under the name Carbon it have many method to access and modifie DateTime php object. To access the month and year of the current day you can access the property month and year directly on the Carbon Object
$today = Carbon::now();
$today->month; // retrieve the month
$today->year; // retrieve the year of the date
In you Controller you can pas the $today object to the method use to render the related view with purpose to have access to that object on a get value of attribute that you want to show in the label field
Laravel come with a prebuilt component to manage Date, and it's know under the name Carbon it have many method to access and modifie DateTime php object. To access the month and year of the current day you can access the property month and year directly on the Carbon Object
$today = Carbon::now();
$today->month; // retrieve the month
$today->year; // retrieve the year of the date
In you Controller you can pas the $today object to the method use to render the related view with purpose to have access to that object on a get value of attribute that you want to show in the label field
edited Nov 20 '18 at 5:34
answered Nov 20 '18 at 5:28
Yves KipondoYves Kipondo
1,398514
1,398514
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386547%2flaravel-getting-current-month-and-year-only%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
How about using jQuery instead of Laravel for month and year?
– Bonish Koirala
Nov 20 '18 at 5:07
How is it gonna work? can you show me a sample code? thank you
– user10665294
Nov 20 '18 at 5:09