Create datetime form dd/mm/yy(yy) [duplicate] - datetime-format

This question already has answers here:
PHP Date Formatting not working wen using date_format()
(2 answers)
Closed 6 years ago.
I try to create datetime form dd/mm/yy(yy), but with no success?
code:
var_dump(date_create("22/12/2016"));
or
var_dump(strtotime("22/12/2016"));
neither works. This is the demo. Why I cannot create from this format?

before date_create convert your date into an acceptable date format
using
DateTime::createFromFormat
(PHP 5 >= 5.3.0, PHP 7)
DateTime::createFromFormat -- date_create_from_format — Parses a time string according to a specified format
var_dump(date_create(DateTime::createFromFormat('d/m/Y', "22/12/2016")->format('Y-m-d')));
Demo

Related

How to fetch data from firestore based on date range in react js. For example: get all documents created between november 5th and november 16th [duplicate]

This question already has answers here:
How to query data between two dates range using Cloud FireStore?
(2 answers)
Firestore query by date range
(13 answers)
Firestore query date range with using 'where'
(1 answer)
Firestore query with timestamp
(1 answer)
Closed 5 months ago.
Unsure how to even approach it. But i am looking for a way to filter documents by a certain date range. The ranges i am looking to query for are: documents created today, this week, this month, and this year.
Any advice is much appreciated

How to delete data in MongoDB by create date? [duplicate]

This question already has answers here:
Find and remove all documents whose "createdDate" is one month older
(1 answer)
Remove old records in mongodb based on Month
(5 answers)
Remove documents from a MongoDB collection based on "time" of a Date field
(2 answers)
Remove old records in mongodb
(3 answers)
I want to retrieve values inserted on particular date using _id of mongodb
(1 answer)
Closed 4 years ago.
I have a MongoDB with 380k documents in it and I want to delete all documents which are created before specific date.
Can anyone help me with writing query for this task?
Thank you.
The ObjectId of the document is basically contains timestamp. So you can easily construct ObjectId from timestamp and use $lt operator just like this (python code):
from bson.objectid import ObjectId
ts = datetime.datetime(2017, 1, 1)
doc_id = ObjectId.from_datetime(ts)
result = collection.find({"_id": {"$lt": doc_id}})

Why does converting a blank string to a date in SQL Server result in 1900-01-01? [duplicate]

This question already has answers here:
SQL cast datetime
(3 answers)
Closed 5 years ago.
Running a simple T-SQL query of SELECT CONVERT(date, '') will render a result of 1900-01-01. It seems to me that it would be more consistent to convert a blank string to either 1753-01-01 (the minimum allowable date value) or NULL. 1900 just seems so arbitrary, but I assume this was a deliberate design choice made by the MS SQL programmers. What is the purpose of this functionality?
It is due to implicit conversion. The 0 date in sql server is 1/1/1900. Any dates earlier than that are a negative number.
SQL Server datetime calendar start point is start of day of 01 January 1900.
https://stackoverflow.com/a/17071583/7974050

remove time from getdate() using SQL [duplicate]

This question already has answers here:
Best approach to remove time part of datetime in SQL Server
(23 answers)
Closed 5 years ago.
I was wondering if anyone new how to remove the time hh,mm,ss from the getdate? I am very new to using SQL and am having trouble. Right now I have the date added so it could always pull the current date and add one day to that. Now I need to remove the time from being shown completely. I do NOT want to change time to 00:00:00, I want it to be completely hidden.
Here is my code:
Select DATEADD(DAY, 1, GETDATE())
Use CAST or CONVERT.
Using CAST
SELECT DATEADD(DAY,1,CAST(GETDATE() as date))
Using CONVERT
SELECT DATEADD(DAY,1,CONVERT(date,GETDATE()))

SQL Server cast a number format to another format [duplicate]

This question already has answers here:
SQL Server Convert a number
(2 answers)
Closed 8 years ago.
I have this number format (I have it as varchar in my table) 6.71307E+15 I want to convert it to this: 6713073544159400.
Is there a way I can do that in SQL Server, because currently I have to do it manually using Excel.
This should give you the closest representation:
SELECT CONVERT(BIGINT, CONVERT(FLOAT, '6.71307E+15'));
Even excel should only result 6713070000000000

Resources