I have a custom profile field "field_date_observed" which has format "2014-10-21". I am trying to set its value using the code further down but am getting the error:
EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityMetadataWrapper->set()
The code:
$todays_date = date('Y-m-d');
$uid=23;
$obj_container = user_load($uid);
$obj = entity_metadata_wrapper('user', $obj_container);
$obj->field_date_observed = $todays_date;
$obj->save();
You need to use UNIX timestamp format to set the date value with entity_medata_wrapper.
Try changing the first line to:
$todays_date = strtotime(date('Y-m-d'));
Related
I'm struggling for hours with this seemingly trivial issue.
I have a antd datepicker on my page.
Whenever I choose a date, instead of giving me the date I chose, it gives me a messy moment object, which I can't figure out how to read.
All I want is that when I choose "2020-01-18", it should give me precisely this string that the user chose, regardless of timezone, preferably in ISO format.
This is not a multi-national website. I just need a plain vanilla date so I can send it to the server, store in db, whatever.
Here are some of my trials, so far no luck:
var fltval = e;
if (isMoment(fltval)) {
var dat = fltval.toDate();
//dat.setUTCHours(0)
fltval = dat.toISOString(); // fltval.toISOString(false)
var a = dat.toUTCString();
//var b = dat.toLocaleString()
}
It keeps on moving with a few hours, probably to compensate for some timezone bias
UPDATE 1:
the datestring is data-wise correct. But its not ISO, so I cant use it correctly. I might try to parse this, but I cannot find a way to parse a string to date with a specific format.
UPDATE 2:
I also tried adding the bias manually, but for some reason the bias is 0
var dat = pickerval.toDate()
var bias = Date.prototype.getTimezoneOffset()// this is 0...
var bias2 = dat.getTimezoneOffset()// and this too is 0
var d2 = new Date(dat.getTime()+bias)
var mystring= dat.toISOString() //still wrong
Thanks!
Javascript date functions can be used,
I assume you are getting in 2022-01-03T11:19:07.946Z format then
date.toISOString().slice(0, 10)
to 2022-01-03
There are 2 ways to get the date string:
Use the moment.format api:
date.format("yyyy-MM-DD")
Use the date string that is passed to the onChange as second parameter
Here is a Link.
I am assuming your code snippet is inside the onChange method. This gives you a moment and a date string to work with (the first and second parameters of the function respectively).
You have a few options. You could set the format prop on the DatePicker to match the format of the string you want. Then just use the date string. Or you can use the moment object as Domino987 described.
I have an issue where I want to display only the hh.mm in da-DK from the NOW() function in AMPscript.
I have tried the following two options.
formatdate(Now(),"","HH.mm","da-DK")
This inputs only time but servertime, ex. 03.16
format(Systemdatetolocaldate(Now()),"","hh.mm")
Correct time but the whole string, ex. 12/10/2020 10:16:44 AM
Anyone with some pointers?
I've found a "quickfix" with the set of
SET #redeemedHour = datePart(Systemdatetolocaldate(Now()),"H")
SET #redeemedMinute = datePart(Systemdatetolocaldate(Now()),"minute")
and then concanate
I implemented a version of the ionic2-Calender. It works very fine. When i have no events in my eventSource and create an Event, the event is displayed correctly.
The Problem comes when I am trying to load Events from my Storage. I am always getting this error:
TypeError: eventStartTime.getFullYear is not a function at
MonthViewComponent.onDataLoaded (ionic2-calendar.js:1768) at
MonthViewComponent.ngOnChanges (ionic2-calendar.js:1614) at
MonthViewComponent.wrapOnChangesHook_inPreviousChangesStorage
Can anyone help me ?
Based on the issue here, it says the startTime property of the event should be a date object.
This indicates that the event startTime probably is not a valid Date
object. Could you double check what's the type of startTime? If it's a
string, you need to convert it into Date object.
I have also stumbled upon this when using web storage to load the calendar, which gets converted to string data type.
The solution is very simple as we only need to iterate through the value from the storage and convert it to date before setting the value of the model itself.
var eventsFromStorage = window.localStorage.get("eventsCalendar");
var countData = eventsFromStorage.length;
for (i = 0; i < countData; i++) {
eventsFromStorage[i].startTime = new Date(eventsFromStorage[i].startTime);
eventsFromStorage[i].endTime = new Date(eventsFromStorage[i].endTime);
}
this.eventsModel = eventsFromStorage;
This is the first time I've asked for help, so apologies if I've got the format or level of detail wrong.
I want the datepicker dates to change their background color for all dates that match a set of dates in an array of dates (highlight_dates). My code works with a manually entered array but NOT for programmatically entered dates.
How I compare dates
To check if a date is in the array I use ‘inArray’ (L11 in the following code):
1. $('#calendar').datepicker({
2. beforeShowDay: function(date){
3. var month = date.getMonth()+1;
4. var year = date.getFullYear();
5. var day = date.getDate();
6. // Change format of date
7. var newdate = day+"-"+month+'-'+year;
8. // Set tooltip text when mouse over date
9. var tooltip_text = "Results available for " + newdate;
10. // Check date in Array
11. if(jQuery.inArray(newdate, highlight_dates) != -1){
12. return [true, "highlight", tooltip_text ];
13. }
14. return [true];
15. }
16. });
(L12 “highlight” calls CSS formatting)
This works OK when I use an array that I create manually (type in) as in:
var highlight_dates = ['10-9-2019','16-5-2019', etc];
All the dates that correspond to the dates in the array change their background color in datepicker - but when I use JSON to get the dates programatically (from an external directory) none of the datepicker dates change color.
How I get the dates from an external directory
I use the following code to get the dates from the directory (calling perl code as in in L4):
1. function getResults() {
2. $.ajax({
3. type: 'POST',
4. url: 'getResultsFilenames5.pl',
5. success: function(res) {
6. //alert("reached L37 and JSON data is : " + res.result);
7. //localStorage.setItem('dateArray', JSON.stringify(res.result));
8. localStorage.setItem('dateArray', res.result);
9. var resultDates = localStorage.getItem('dateArray')
10. //var resultDates = JSON.parse(localStorage.getItem('dateArray'));
11. },
12. error: function() {alert("something didn't work!!");
13. }
14. });
15. }
The results are placed in localStorage (L8) so that they can be retrieved when needed.
The results I'm getting
When I display the dates (L6) - THE OUTPUT FROM res.result - they look like this:
23-05-2019,07-10-2019,20-06-2019,01-06-2019,30-05-2019,29-04-2019,,25-04-2019,03-10-2019,16-05-2019,,17-06-2019 (no square brackets or apostrophes).
However, with the addition of square brackets, and apostrophes in the perl code (which retrieves the dates) the array of dates look exactly like the manual array when I display them using an ‘alert’ (L 6), so I think that the problem is not to do with the programming but more likely a formatting mismatch between the datepicker format and either the format returned by JSON or by the use of localStorage.
I’ve tried using ‘stringify’ (L7) and ‘parse’ (L10) to change the date format but that hasn’t had any effect. I’ve also (in desperation) tried changing the perl output to scalar (using ‘qq(#files’) – but again without getting the dates to highlight.
I don’t know what to do to solve the problem and I’d be grateful for any advice that you can offer.
You should transform the data to a valid array, then set it to resultDates and then store the data to the storage.
success: function(res) {
var resultDates = getDataAsArray(res);
localStorage.setItem('dateArray', resultDates);
},
and an small helper function:
function getDataAsArray(data) {
return data.split(",");
}
I have to create XML from Java objects and I use the Simple framework.
My problem is I need to send some names in camel case:
#Element
String ChannelData
and the xml element produced is:
<channel-data>
Which is rejected by the receiver, it needs to be
<channelData>
I cannot find a way to configure this, I tried adding the name explicitly:
#Elenemt(name="channelData")
but without success.
Ok I solved it.
I actuallt initialized the Persister with the wrong format:
Format format = new Format(0, null, new HyphenStyle(), Verbosity.HIGH);
Instead of:
Format format = new Format(0, null, new CamelCaseStyle(), Verbosity.HIGH);