How to select format date using carbon? - laravel

How to select format date using carbon ?
I'm used format ->select(DB::raw("(DATE_FORMAT(score_dt, '%M'))")) before.
I want to change the format by using carbon, how do I use it in a select query? to display month name

Have a read of the Carbon docs. Laravel uses Carbon 2 now.
You should be able to get the month name with the monthName property: $yourDateObject->monthName.
Carbon, however, is a PHP library and is not part of the database you're using. This means you can't use it in your select query, to use Carbon, you'll need to format your data in your model/controller/frontend. This is a fairly standard way of turning ISO8601 dates into human readable form.

Related

Changing format of date without using to_char - Oracle

I have to get the max payment date on an invoice and I am having trouble with the date format. I do not need the max in this formula as I am using the format in a reporting tool that is pulling the max from what it finds for me.
Using "to_char({datefield},'mm/dd/yyyy')" works for displaying that date the way we would like BUT when you use summary function MAX it does not pull the correct date because it is looking at a string and not a date (it will think 12/3/21 is larger than 3/2/22).
Another thing I have tried is trunc - "trunc({datefield})" which gives us the correct max date but it changes the formatting. For example if the date prior to the formula being applied is "8/12/21 12:00:00:000" the trunc formula will display it as 12-08-21 which is horribly wrong.
Long story short is I need a way to change a date/time to date with the format of 'mmmm/dd/yyyy' WITHOUT converting it to a string with something like to_char. Thank you!!!!
A DATE is a binary data type consisting of 7 bytes representing: century, year-of-century, month, day, hour, minute and second. It ALWAYS has all of those components and it is NEVER stored with any (human-readable) format.
What you are seeing when a date is displayed is the client application you are using to access the database making a decision to be helpful to you, the user, and display the binary DATE provided by the database in a human-readable format.
If you want to change how the DATE is displayed then you either need to:
Change the settings on the client application that controls how it formats dates when it displays them to you; or
Change the data-type so that it is no longer a DATE (which does not have a format) to a data type where the values of the date can be formatted (such as a string). You can do this using TO_CHAR.
If you want to find the maximum then do it BEFORE applying the formatting:
SELECT TO_CHAR(MAX({datefield}),'mm/dd/yyyy')
FROM your_table;

Laravel 5.8 - Validate future date

How do I validate that a given date is in the future and not a past date? Alternatively, does Html 5 allows one to disable past date from a date field?
I have a form in my app that allows user to select start date for an event from an HTML date input field. I want users to only choose a date in the future and not a past date.
I think you can use it like this:
$rules = [
'start_date' => 'date_format:d/m/Y|after:3/13/2019',
];
See also the laravel documentation:
https://laravel.com/docs/5.8/validation#rule-after
or
https://laravel.com/docs/5.8/validation#rule-after-or-equal
after:today works as #Tim Lewis commented above.
As for HTML validation, date fields still aren't fully supported. Safari being the main culprit.
You can use min="2020-01-01" format against the input, but you'll need to either add that date server-side or using JavaScript so it's tomorrow's date.
I have tried code and found that if you want to validate only year than you can write something like
$rules = ['dob'=>'required|date_format:Y|before:today']
where,
date_format
is fixed keyword and with help of 'Y' you can validate only year
and before:today validate if year is older than today or not.
you can use d-m-Y format instead only Y.
happy coding...

Formatting a date column in powerpointwriter

I am using PowerpointWriter to populate a ppt table. I have currency and date columns that need to be formatted (not with colors/fonts/etc). For example, the date column needs to be the date only, not the time.
How do I do this?
Thanks,
Cheri
PowerPointWriter does not support that kind of formatting at the moment. You should consider formatting your data in your application before binding the data to the PowerPoint file using PowerPointWriter..

Date translation using Free marker Syntax in Netsuite Advance PDF template

I have a dilemma, we are a multi subsidiary company with subsidiaries in different countries/jurisdictions. All of which requires specific language and formatting for invoices/credit memos depending on the subsidiary. Currently our global date format is mm/dd/yyyy and it is flowing correctly to the template, we want to show the Transaction and Due (${record.trandate} +${record.duedate})in DD-Mon-YYYY (01-Jan-20015) without changing the global date preference. AS per NS support if we change the date preference globally it may effect our existing forms and scripts.
Is there any Free Marker syntax that can translate the date format for those to fields from mm/dd/yyyy to DD-Mon-YY, any help is appreciated.
Sam Azad
Also by adding <#setting date_format="dd-MMM-yyyy"/> in the head section also does the trick.

How to format birt date report parameter?

By default if the input parameter to BIRT report is of type Date, it takes yyyy-MM-dd format.
Can we change to something else e.g. may be dd/MM/yyyy ?
You can change the input format for a date parameter. Click on "Change..." select Format as "Custom" and you can enter a valid format code as you like.
If you want to enter a default Date you still have to use the yyyy-MM-dd Format, this cannot be changed ( where I used new Date() in the Picture), but the output format will still be your entered format.
Another option is to use the format Date Time section in the Birt designer and choose the right locale and formatting for the date.
I have done it in Birt 3.7 and works fine
There can be many way to do that but the easy one is you can do this in SQL Query itself.
If you are using DB2 you may try
VARCHAR_FORMAT("Your Column Mapping Name",'DD-Mon-YYYY') AS dataSetName.
But this will change its Data type to String
Try if this make any seance.

Resources