I am new to D3.js. I have a date string like "01 DEC 2017". I need to fetch year from it. I am using time format. It's returning null. What is wrong in my code ? Advance thanks for any help.
My code :
d.date = d3.time.format("%Y-%m-%d").parse("01 DEC 2017").getFullYear();
Related
I have a date that is coming from database (type date):
2018-08-25
This date is in french timezone.
When I do:
$from = Carbon::parse("2018-08-25", 'Europe/Paris');
$from->timezone('UTC');
dd($from);
I get:
date: 2018-08-24 22:00:00.0 UTC (+00:00)
Which is what I want
But when I use field from DB:
$operation = Operation::findOrFail($request->operation);
$from = Carbon::parse($operation->date_ini, 'Europe/Paris');
$from->timezone('UTC');
dd($from);
I get:
date: 2018-08-25 00:00:00.0 UTC (+00:00)
In my DB, field is saved as : 2018-08-25, so literraly, it means 2018-08-25 UTC. So result is coherent. But I'm not sure how to deal with it to get what I want. The implication would be that I have to store my date like a datetime in DB so that I can store it in UTC with 1 or 2 hours less. Is there anyway to avoid this and keep it simple ?
Any idea ?
I solved it using:
$from = Carbon::parse($operation->date_ini)->shiftTimezone('Europe/Paris');;
shiftTimezone with change timezone without changing the date. So, it do the trick for me !
If you call setTimezone() on an existing instance of Carbon, it will change the date/time to the new timezone, for example
$changeTimeZone = \Carbon\Carbon::parse($operation->date_ini)->setTimezone('Asia/Dhaka')->format('H:i');
In my Laravel 5.8 application, I to convert date in string format like
02 May, 2019 to date time using Carbon. I try like :
setlocale(LC_TIME, 'en');
$filter_check_in_datepicker_till = Carbon::createFromFormat( 'dd MMMM YYY', $filter_check_in_datepicker_till )->locale('en_EN');;
But got error:
"message": "Unexpected data found.\nA textual month could not be found\nData missing",
Which is right way?
Thanks!
The Carbon docs say:
createFromFormat() is mostly a wrapper for the base php function DateTime::createFromFormat.
It isn't entirely clear from the docs, but that means the $format parameter passed to createFromFormat() is a DateTime format, not a Carbon format. So instead of dd MMMM YYY, you should use d, M Y (check the DateTime format reference):
\Carbon\Carbon::createFromFormat('d, M Y', '02, May 2019');
// returns 2019-05-02 12:48:26
For reference, there are several problems in your Carbon format, so even if createFromFormat took a Carbon format string what you have would not work. Checking the Carbon format reference:
dd is actually "Minified day name (from Su to Sa), transatable". You really want DD for the zero-padded day of month;
The date format you are using includes a comma, but your format string is missing that;
YYY is not actually a valid Carbon format string. You really wanted YYYY for 4-digit year;
I've this document stored in mongo:
{
"_id" : "cpd4-734fc2db-a5b0-4881-b5d7-bf85d894178d",
"expiresAt" : ISODate("2018-10-10T00:00:00Z")
}
In order to get sure, all data is right, I've got first the document and I've log some data:
Reference ref = this.mongoTemplate.findById("cpd4-734fc2db-a5b0-4881-b5d7-bf85d894178d", Reference.class);
LOG.info(ref.getExpiresAt().toString());
LOG.info(Long.toString(ref.getExpiresAt().getTime()));
The result is:
Wed Oct 10 02:00:00 CEST 2018 <<<<<<<<<<<<<<<<<<<
1539129600000
As you can see when I get the object, the expiresAt field is 02:00:00 instead of 00:00:00.
Value in database is expiresAt field is: ISODate("2018-10-10T00:00:00Z")
Any ideas or thoughts welcome for this issue!
This date is in Zulu time (note the 'Z' on the end):
ISODate("2018-10-10T00:00:00Z")
When you do this, specifically the call to .toString(), you are converting the date into a local date string in your time zone, which appears to be Zulu+2:
LOG.info(ref.getExpiresAt().toString());
I usually set my server's time zone to UTC/Zulu/GMT, in order to avoid any automatic timezone conversions happening like this.
I have an MSSQL Database table with Date field. When selecting that field with codeigniter, it returns a formatted date different from the format found in the database. What I need is for the CI model to return the original date format so I can format the date as I needed.
TSQL returns
2018-05-18
Displayed as HTML
May 18, 2018 12:00:00:AM
I need to display as is
2018-05-18
Hope this will help you :
$returned_date ='May 18, 2018 12:00:00:AM';
$date = DateTime::createFromFormat('M d, Y H:i:s:A', $returned_date);
echo $date->format('Y-m-d');
/*Output 2018-05-18*/
Working example : https://eval.in/1005671
For more : http://php.net/manual/en/datetime.createfromformat.php
When you are displaying it on your html/php please use below code to format your date string:
$newDate = date("Y-m-d", strtotime($originalDate));
As my first exploration in D3.js,there is a datefield in the csv defined as '01/12/2016'.how to convert this to a proper d3.TimeFormat ?
Your Format is DD/MM/YYYY(01/12/2016)
Use the Following d3 time Format
var parseDate = d3.time.format("%d/%m/%Y").parse;
parseDate('YOUR DATE FORMAT');