SharePoint wcf-services JSON DateTime format parsing in C# - sharepoint

I am trying to read some data from the SharePoint API via the older _vti_bin/client.svc endpoint
I can't seem to find what type of date format this is and how I can parse it via C#.
The timestamp being returned is:
"LastContentModifiedDate": "/Date(2022,3,18,13,12,28,990)/"
The year and month are obvious so I could parse it myself if I knew what all the values are. Is there a formal definition for this or a way to parse this reliably? Is this a DateTime or DateTimeOffset or something else?
I just get an exception when trying to deserialize to a DateTime or DateTimeOffset.

The /Date(...)/ format is Microsoft's built-in JSON date format.
You can try to parse it using the code below.You can also check out this post, which provides a lot of methods.
using System.Web.Script.Serialization;
//code
JavaScriptSerializer json_serializer = new JavaScriptSerializer();
DateTime ddate = json_serializer.Deserialize<DateTime>(#"""\/Date(1326038400000)\/""").ToLocalTime();

Related

Changing datetime format in py

I have the following code which gives the following output:
print(df1['Diff'].mean())
outputs:
10 days 16:13:29.467455
But since i just want the days value and not the time, i have done this:
print(datetime.strptime(df1['Diff'].mean(), format ='%d')
but i am getting the following error:
^
SyntaxError: unexpected EOF while parsing
Why am i getting this error?
For date, time, and datetime objects
You should be using strftime to format the time, not to parse the time (as in strptime).
print(obj.strftime('%d'))
strptime expects a string to be passed in (and you were passing in a datetime object), whereas strftime formats an existing datetime object.
For timedelta objects
print(obj.days)
This gets the days counterpart you're looking for.
I think the instance of df1['Diff'].mean() is str and datetime.strptime() can be use only in datetime methods. So to only get date you have to take slice of df1['Diff'].mean() like df1['Diff'].mean()[:-14]
Which is in your case.

Transform a string to some code in python 3

I store some data in a excel that I extract in a JSON format. I also call some data with GET requests from some API I created. With all these data, I do some test (does the data in the excel = the data returned by the API?)
In my case, I may need to store in the excel the way to select the data from the API json returned by the GET.
for example, the API returns :
{"countries":
[{"code":"AF","name":"Afghanistan"},
{"code":"AX","name":"Ă…land Islands"} ...
And in my excel, I store :
excelData['countries'][0]['name']
I can retrieve the excelData['countries'][0]['name'] in my code just fine, as a string.
Is there a way to convert excelData['countries'][0]['name'] from a string to some code that actually points and get the data I need from the API json?
here's how I want to use it :
self.assertEqual(str(valueExcel), path)
#path is the string from the excel that tells where to fetch the data from the
# JSON api
I thought strings would be interpreted but no :
AssertionError: 'AF' != "excelData['countries'][0]['code']"
- AF
+ excelData['countries'][0]['code']
You are looking for the eval method. Try with this:
self.assertEqual(str(valueExcel), eval(path))
Important: Keep in mind that eval can be dangerous, since malicious code could be executed. More warnings here: What does Python's eval() do?

How to parse specific date format with strptime?

I am using python3 and I have a time data format like '01-FEB-17' and I need to parse it with datetime.strptime. Does anyone know which format is the correct for this? I tried '%d-%b-%Y', '%d-%m-%Y',... and none of them worked.
Thanks
You can use this
from datetime import datetime
t = datetime.strptime('01-FEB-17', '%d-%b-%y')
NOTE: You can head here for a full list of format specifiers to use

Cast String to date time in Stream analytics Query

We are sending datetime as string in the format 2018-03-20 10:50:037.996, and we have written Steam analytics query as below.
SELECT
powerscout.Device_Id AS PowerScout,
powerscout.[kW System],
CAST(powerscout.[TimeStamp] AS datetime) AS [TimeStamp]
INTO
[PowergridView]
FROM
[IoTHubIn]
When we are sending data through Stream analytics, Job is getting failed.
Any Suggestions please.
Thanks In Advance
ASA can parse DATETIME fields represented in one of the formats described in ISO 8601. This format is not supported. You can try using custom JavaScript function to parse it.

I am having weather data in grib2 format and i want to convert it into json format Is it possible to conversion using node.js?

I am having weather data in grib2 format and i want to convert it into json format or csv. I know the languages PHP , node.js. Is it possible to conversion using these technologies?
Using Nodejs try this package may help you
https://www.npmjs.com/package/grib2json

Resources