I Have a problem with the created_at and other carbon dates, when I do
return $return_items['created_date'] = $item->created_at;
It returns '2016-07-26 13:19:55'
but if I do
return $return_items;
it returns
"created_date": {
"date": "2016-07-26 13:22:17.000000"
"timezone_type": 3
"timezone": "UTC"
}
How can I solve this, to only show the string date?
thanks
$object->created_at->timestamp
$object->created_at->format('d M Y - H:i:s')
Try this below code,
$dateOnly = new DateTime($item->created_at);
echo $dateOnly ->format('Y-m-d');
For example, display the date in the format you want and the hour, minutes and seconds :
{{ $user->created_at->format('d M Y - H:i:s') }}
Or only date:
{{ $user->created_at->format('d M Y') }}
More info, in the documentation Laravel Date Casting and Carbon
Related
I am working with the Graph API and trying to create events using the C# Microsoft.Graph API. Let's assume to have the following Microsoft.Graph.Event objects:
{
Subject = "A Title",
Body = new ItemBody(),
Start = {
DateTime = "2022-10-24T00:00:00",
TimeZone = "W. Europe Standard Time"
},
End ={
DateTime = "2022-10-25T00:00:00",
TimeZone = "W. Europe Standard Time"
},
IsAllDay = true,
},{
Subject = "B Title",
Body = new ItemBody(),
Start = new DateTimeTimeZone {
DateTime = "2022-10-28T13:30:00",
TimeZone = "W. Europe Standard Time"
},
End = new DateTimeTimeZone {
DateTime = "2022-10-28T16:45:00",
TimeZone = "W. Europe Standard Time"
},
IsAllDay = false,
}
They are successfully written into my calendar trough twice call to:
await _graphServiceClient.Users[emailAddress].Events.Request().AddAsync(graphEvent);
and I see:
and
which is the expected behaviour.
Querying the API with the filter "start/dateTime ge '2022-10-24T00:00:00'" I get just B Title, A Title is missing. Furthermore the start and end dates are wrong, I get 2022-10-28T11:30:00.0000000 and 2022-10-28T14:45:00.0000000.
If I edit the query to "start/dateTime ge '2022-10-23T00:00:00'" I get both, the dates of B title are the same (wrong), but the ones of A Title ar correct 2022-10-24T00:00:00.0000000 and 2022-10-25T00:00:00.0000000.
I expected that B Title has 2022-10-28T13:30:00.0000000 and 2022-10-28T16:45:00.0000000. What am I doing wrong?
When you call list events endpoint you can specify request header Prefer: outlook.timezone="<time-zone>". If not specified, those time values are returned in UTC.
Example:
var events = await _graphServiceClient.Users[emailAddress]
.Events
.Request()
.Header("Prefer","outlook.timezone=\"W. Europe Standard Time\"")
.GetAsync();
I guess that with the correct outlook.timezone header your query will return also A Title and correct time values.
References:
Calendar list events - request headers
I need an average count of records group by date, I am using Elasticsearch and searchkick with Ruby on rails.
For getting records group by date Following code is working:
group_by_date: {
date_histogram: {
field: :created_at,
interval: 'day'
}
},
I am getting the following output of this code
"group_by_date"=>
{"buckets"=>
[{"key_as_string"=>"2020-01-07T00:00:00.000Z",
"key"=>1578355200000,
"doc_count"=>14},
{"key_as_string"=>"2020-01-08T00:00:00.000Z",
"key"=>1578441600000,
"doc_count"=>3}
]
}
I want an average of these records here in this case there are two dates So the average should be (14 + 3)/2 = 8.5
Thanks
I got the average by following
average_properties_by_date:{
avg_bucket: {
buckets_path: 'group_by_date>_count',
gap_policy: "skip",
format: "#,##0.00;(#,##0.00)"
}
}
Be careful here _count will be used instead of doc_count.
createdBy: "f201b814-34c2-4948-9ab2-36a2293d7098"
eventID: 5
forumDescription: "Android Forum 01 Description"
forumID: 1
forumStatus: 3
forumTitle: "Android Forum 01"
lastModifiedDateTime: "/Date(1413427128000+0530)/"
version: 3
}
1: {
createdBy: "f201b814-34c2-4948-9ab2-36a2293d7098"
eventID: 5
forumDescription: "Android sdasdasd 02"
forumID: 2
forumStatus: 3
forumTitle: "Android Forum 02"
lastModifiedDateTime: "/Date(1413427135000+0530)/"
version: 3
Create Unix timestamp and then use that. Unix timestamp is count of millisecond from 1/1/1970.
For creating timestamp in C# use this:
public string ToUnixEpoch(DateTime dateTime)
{
DateTime d1 = new DateTime(1970, 1, 1);
DateTime d2 = dateTime.ToUniversalTime();
TimeSpan ts = new TimeSpan(d2.Ticks - d1.Ticks);
return ts.TotalMilliseconds.ToString("#");
}
For more info see this. Hope this helps... :)
With jQuery TableSorter, I can't filter a column correctly that contains European formatted digits (dot every 3 digit and comma as decimal sign). Anyway, sorting work like a charm.
See my problem here : http://jsfiddle.net/Ted22/9tBgZ/13/
I work with this piece of code :
jQuery.tablesorter.addParser({
id: "commaDigit",
is: function(s, table) {
var c = table.config;
return $.tablesorter.isDigit(s.replace(/[,.]/g, ""), c);
},
format: function(s) {
return $.tablesorter.formatFloat(s.replace(/[,.]/g, ""));
},
parsed: false,
type: "numeric"
});
Can you help me ?
Thanks in adavance !
Ted
Just set the usNumberFormat option to false (demo)
I have a simple datetime attribute to pick a date like this on the views
= f.date_select :period_end_at, default: { day: 31 }
It defaults to last day of the month as the example. The problem is that if month selected is "June" that has 30 days, since there is no '31' day for June, it will save the object as day 1 instead of day 30.
Is there an easy way to always save to the highest day of the month if the value provided is above all available for that moonth?
Not sure if it could be shortened, but this should work (if I understood your question correctly):
= f.date_select :period_end_at, default: { day: Time.days_in_month(Time.now.month) }
Take a look at this js snippet, it works well for me with Rails 4.2.0
<script>
$(function(){
railsMonthDates();
$("select[id*=_2i], select[id*=_1i]").change( railsMonthDates );
});
function railsMonthDates() {
$("select[id*=_2i]").each(function(){
$monthSelect = $(this);
$daySelect = $(this).siblings("select[id*=_3i]");
$yearSelect = $(this).siblings("select[id*=_1i]");
var year = parseInt($yearSelect.val());
var month = parseInt($monthSelect.val());
var days = new Date(year, month, 0).getDate();
var selectedDay = $daySelect.val()
$daySelect.html('');
for(var i=1; i<=days; i++) {
$daySelect.append('<option value="'+i+'">'+i+'</option>');
}
$daySelect.val(selectedDay);
});
}
</script>
Simply paste it into the partial which has the form.
Pay attention, it match every element which has id*=_1i, id*=_2i or id*=_3i, so if you have more f.date_select you need to specify a better matcher.