How can we identify the timezone of date & time we are getting in MS Graph API response? - microsoft-graph-onenote

I am getting the following response from MS Graph API while fetching all sections.
(
[id] => 0-92b00000!86-AAAAAAAAAAAF1FC8!132
[self] => https://graph.microsoft.com/v1.0/users/testtt
[createdDateTime] => 2021-03-19T09:37:35Z
[title] => ABCDEF
[createdByAppId] =>
[contentUrl] => https://graph.microsoft.com/v1.0/users/aaaaa
[lastModifiedDateTime] => 2021-03-19T09:37:49Z
)
In the above part of response, I want to identify the timezone of the server or this "lastModifiedDateTime".
Advance thanks for your help.

The "Z" suffix on the lastModifiedDateTime field means the timestamp is in UTC, or Coordinated Universal Time, sometimes called "Zulu".
The timestamp represents date and time information using ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z.
Reference

Related

What data type should be used for timestamp in DynamoDB?

I am new to DynamoDB. I wish to create a table which using DeviceID as the hash key, Timestamp as my range key and some data.
{ DeviceID: 123, Timestamp: "2016-11-11T17:21:07.5272333Z", X: 12, Y: 35 }
In SQL, we can use datetime type for Timestamp, but in DynamoDB there is none.
What data type should I use? String? Number?
For the chosen data type, what kind of timestamp format should I write in? ISO format (e.g: 2016-11-11T17:21:07.5272333Z) or epoch time (e.g: 1478943038816)?
I need to search through the table through a range of time, e.g: 1/1/2015 10:00:00am until 31/12/2016 11:00:00pm
The String data type should be used for Date or Timestamp.
You can use the String data type to represent a date or a timestamp.
One way to do this is by using ISO 8601 strings, as shown in these
examples:
2016-02-15
2015-12-21T17:42:34Z
20150311T122706Z
DynamoDB Data type for Date or Timestamp
Yes, the Range queries are supported when the date is stored as String. The BETWEEN can be used on FilterExpresssion. I have got the items in the result using the below filter expressions.
FilterExpression without time:-
FilterExpression : 'createdate between :val1 and :val2',
ExpressionAttributeValues : {
':hkey' : year_val,
':rkey' : title,
":val1" : "2010-01-01",
":val2" : "2010-12-31"
}
FilterExpression with time:-
FilterExpression : 'createdate between :val1 and :val2',
ExpressionAttributeValues : {
':hkey' : year_val,
':rkey' : title,
":val1" : "2010-01-01T00:00:00",
":val2" : "2010-12-31T00:00:00"
}
Database Values:-
Format 1 - with timezone:
{"Item":{"createdate":{"S":"2010-12-21T17:42:34+00:00"},"title":{"S":"The Big New Movie 2010"},"yearkey":{"N":"2010"},"info":{"M":{"rating":{"N":"0"},"plot":{"S":"Nothing happens at all."}}}}}
Format 2 - without timezone:-
{"Item":{"createdate":{"S":"2010-12-21T17:42:34Z"},"title":{"S":"The Big New Movie 2010"},"yearkey":{"N":"2010"},"info":{"M":{"rating":{"N":"0"},"plot":{"S":"Nothing happens at all."}}}}}
Data type depends on your requirements.
You may use String using ISO format or Number using epoch format.
The advantage of ISO format (String) is human readability however DynamoDB does not support Time To Live (TTL) for this format. All filters work such as 'between' and 'range' as explained by notionquest.
Time To Live (TTL) for DynamoDB allows you to define when items in a table expire so that they can be automatically deleted from the database.
The advantage of using epoch format (Number) is that you can use the TTL feature and all filters.
TLDR;
Epoch format (Number type) - Can use Time To Live
ISO format (String type) - Cannot use Time To Live but is more human readable
for me to be able to filter out results when sending a query request, I used epoch format for DateTime, it is more efficient than using string.
imagine these scenarios: last 31 days, last 24 hours, ... again all is possible using the string format since it also has begins_with operator(please check 3rd example in below link on AWS doc) but numeric values are much more efficient in terms of performance while sorting(comparing) & calculation.
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.KeyConditionExpressions
it is easy to convert date-time to epoch format
Javascript:
var date = new Date();
var epoch = date.getTime();
// converting back to date-time
var initial_date = new Date(epoch);
C#
var date = DateTime.UtcNow;
var epoch = new DateTimeOffset(date).ToUnixTimeSeconds();
// converting back to date-time
var initial_date = DateTimeOffset.FromUnixTimeSeconds(epoch);
Python
import time
epoch = time.time()
# converting back to date-time
initial_date = time.gmtime(epoch )
The Number data type OR the String data type
can be used for Date or Timestamp - not just String as the Accepted Answer on this Question incorrectly singles out while ignoring Number.
You can use the number data type to represent a date or a timestamp. One way to do this is by using epoch timeā€”the number of seconds since 00:00:00 UTC on 1 January 1970. For example, the epoch time 1437136300 represents 12:31:40 PM UTC on 17 July 2015.
For more information, see http://en.wikipedia.org/wiki/Unix_time.
...
You can use the String data type to represent a date or a timestamp. One way to do this is by using ISO 8601 strings, as shown in these examples:
2016-02-15
2015-12-21T17:42:34Z
20150311T122706Z
For more information, see http://en.wikipedia.org/wiki/ISO_8601.
DynamoDB Data type for Date or Timestamp

How to fetch past 30 days data from dynamo db

I want to fetch the past 30 days data from dynamo db. I can only able to fetch only one id at a time. How can i get all the data of 30 days from dynamo db.
$sevenDaysAgo = date('Y-m-d H:i:s', strtotime('30 days'));
echo $response = $dynamodb->query([ 'TableName' => 'notifications',
'KeyConditionExpression' => 'id = :id and date_time >= :datess', 'ExpressionAttributeValues' => [ ':id' => ['S' => '350'],
':datess' => ['S' => $sevenDaysAgo] ],
'ProjectionExpression' => 'id', 'ConsistentRead' => true ]);
You could use the new TTL feature, Streams, and Lambda to maintain a sliding 30 day window of data in a new table called sliding. Steps:
Create a new table called sliding with the same schema as your base table. This table should have TTL enabled on an attribute named myttl.
Enable your original table's DynamoDB Stream with both old and new images.
Attach a lambda function to your original table's Stream. This lambda would write all item creations/updates/deletions from the base table to the sliding table.
It seems like each item might already contain a timestamp. Scan your original table and add a N attribute called myttl equal to timestamp+30 days in epoch time, if the item's timestamp was in the last 30 days.
The result of steps 1-4 will be a table sliding that contains an eventually consistent view of the last 30 days worth of data.

Select records having appointment date exactly after 12 hours from current datetime

I want to select all the records from database table whose date time(AppointmentDate column) is equal to current date time + 12 hours.
so basically the records having appointment date which are exactly after 12 hours from current datetime.
how can we write this query in linq to entites?
Thanks in advance.
Pretty straight forward:
var twelveHoursFromNow = DateTime.Now.AddHours(12);
db.Records.Where(m => m.AppointmentDate == twelveHoursFromNow);
However, the equal may be a bit restrictive. As DateTime.Now could be 12:45:30am causing you to discard an appointment at 12:45:00pm. More likely than not, you're going to want a range.
db.Records.Where(m => m.AppointmentDate > rangeStartDateTime && m.AppointmentDate < rangeEndDateTime);

Query with date range

I have the following query;
foreach (Item sourceChild in source.Axes.GetDescendants()
.OrderBy(x => x["date-optional-1"])
.ThenBy(x => x["date-optional-2"])
.Reverse())
{..}
date-optional-1 and 2 are, as the name states, optional, and therefore not guaranteed to be filed.
But if they are, no 1 takes precedence over 2.
I need to add, that if no 1 is filed, then I only need the items from today and forward (it is an event date). How would i go about this in a Where()?
foreach (Item sourceChild in source.Axes.GetDescendants()
.Where(x => DateUtil.ParseDateTime(x["date-optional-1"], DateTime.MaxValue) >= DateTime.UtcNow.Date)
.OrderBy(x => x["date-optional-1"])
.ThenBy(x => x["date-optional-2"])
.Reverse())
{..}
DateUtil.ParseDateTime converts the string value of the 'date-optional-1' field into a DateTime.
Sitecore stores dates in UTC so we compare that DateTime value with DateTime.UtcNow.Date. This includes only items with a 'date-optional-1' value >= today in the result set.
DateTime.MaxValue is passed as the second parameter to DateUtil.ParseDateTime so that items with no 'date-optional-1' value are included in the result set.

Returning a date with time, when passed utc_date and timezone as input

I have an Oracle table which has a date column ( say its name is start_date) that has stored date as UTC date. I have another column that stores a timezone (like 'America/Los_Angeles'). My requirement is I need to display the date column with timestamp corresponding to the timezone stored in the timezone column.
I initially wrote a function that accepts utc_date and the timezone and returns the date as below:
return utc_date + (SUBSTR (TZ_OFFSET (timezone), 1, 1) || '1')
* TO_DSINTERVAL (
'0 '
|| SUBSTR (TZ_OFFSET (timezone), 2, 5)
|| ':00');
but I realized a flaw. It calculates offset based on current time. So it now returns -00 08:00:00.000000 for Los_Angeles. But if the date stored in the utc_date was a date when daylight was enforced, the tz_offset value is not valid anymore. Can someone provide me some pointers how can I approach this problem?
I found a solution to my problem. Instead of relying on TZ_OFFSET, I decided to do the following
return cast(from_tz(cast(utc_date as timestamp),'UTC') at time zone timezone as date);
This is returning me the desired date. If anyone see a flaw let me know

Resources