Convert simple date into SQLite datetime format? - date

I have date in new Date() format. I need to convert to SQLite date time format.(2014-01-05T00:00:00.000Z). Is it possible to do so??
var date = new Date();
now I need to convert this date to SQLite datetime format like (2014-01-05T00:00:00.000Z).

Try:
var date = new Date();
var sqllite_date = date.toISOString();

Use this
// Create an instance of the Date class
var date = new Date();
// Convert it to an ISO string
var sqliteDate = Date.toISOString();
take a look at this W3schools

You can use strftime, from date and time functions.
SELECT strftime('%d-%m-%Y', 'now')
Output
10-06-2010
Hope this helps ..:)

Related

how to convert a time eg- 22:00:00 to a timestamp + include next day date in Flutter

I want to ask how to convert a given time for example 22:00:00 into a timestamp and also add the next day date to it while converting into a time stamp in flutter.
Thank You
You can convert a Date string to a timestamp
convertDateTimeToTimestamp(String yourDateTime, [Duration? extraDuration]) {
DateTime date = DateTime.parse(yourDateTime);
if (extraDuration != null) {
date = date.add(extraDuration);
}
return date.microsecondsSinceEpoch;
}
then your example with one additional day (next day) can be:
main() {
final timestamp = convertDateTimeToTimestamp(
"2022-03-05 22:00:00",
Duration(days: 1),
);
print(timestamp); //output: 1646600400000000
// try to check the converted timestamp with addition duration in the example above, it's only one day
DateTime date = DateTime.fromMicrosecondsSinceEpoch(timestamp);
print('${date.year}-${date.month}-${date.day} ${date.hour}:${date.minute}:${date.second}'); //output: 2022-3-6 22:0:0
}
you can use intl package and format your datetime easier.
Timestamp data type is defined in cloud_firestore.
What do you mean by timestamp?

Comparing calendar datetime to yyyy-mm-dd format in flutter

I have a calendar and in the calendar events are added in here
Map<DateTime, List<EventStore>> get events => _events;
where EventStore is anotherClass like this,
class EventStore{
String subject;
String level;
String room;
EventStore({this.subject,this.level,this.room});
}
Now, I want to compare today's date in yyyy-mm-dd format with the calendar date format. And I also don't know how to see the calendar date format.
How do I compare today's date in yyyy-mm-dd format with the calendar date format? So that I can show all the events that are on the particular date anywhere in my app?
And can anybody say, what is the DateTime format in map,
Map<DateTime, List<EventStore>> get events => _events;
DateTime objects don't contain a date format, it's technically a number of elapsed time since 01-01-1970 https://api.flutter.dev/flutter/dart-core/DateTime-class.html
You can compare DateTime objects using their attributes.
DateTime savedDateTime = getSavedDateFromServer();
DateTime now = DateTime.now();
bool isSameYear = savedDateTime.year == now.year;
bool isSameMonth = savedDateTime.month == now.month;
//etc.
If you want to group your objects by date I recommend you take a look at this:
Flutter/Dart how to groupBy list of maps

Querying mongoTemplate using date

I am trying to find all rows before a certain date using mongoTemplate in Spring Java. This is returning no rows though there are lots of old records.
What is the problem?
Calendar cal = GregorianCalendar.getInstance();
cal.add( Calendar.DAY_OF_YEAR, -73);
Date prevDate = cal.getTime();
List<AuditTrailDTO> dt = mongoTemplate.find(Query.query(Criteria.where("AUDIT_CREATE_DATETIME").lte(prevDate)), AuditTrailDTO.class);
AUDIT_CREATE_DATETIME in Mongo DB is stored in this format:
Audit_Create_DateTime:2019-07-10 08:47:02.078
It should work if the type of Audit_Create_DateTime is Date, so I assume Audit_Create_DateTime is of String type.
You can do the following to do a less-than-equals logic on a String field;
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Query query = Query.query(Criteria.where("AUDIT_CREATE_DATETIME").lte(dateFormat.format(prevDate)));
List<AuditTrailDTO> dt = mongoTemplate.find(query, Customer.class);
which will return proper results, though I recommend properly storing Date values as correct type rather than in String type.

Change input Date format? Vuejs + mongoose

Problem: Change the Date input field from "mm/dd/yyyy" to "dd/mm/yyyy".
I already know how to change after i receive the date, but the problem is that when the client is typing the input is still receiving "mm/dd/yyyy".
My mongoose schema:
const schemaRegister = new mongoose.Schema({
date: Date,
});
My input area:
<b-form-input v-mask="'##/##/####'" v-model="date"></b-form-input>
My date formating (using momentsjs):
changeDateFormat() {
let fixedDate = moment(this.registers[i].date).format("L");
this.registers[i].date = fixedDate;
}
I am displaying the 'fixedDate' on the table, but it doesn't help a lot because when the client is typing he thinks the first 2 slots are the days (dd), but in reality they are the month (mm). As a solution i thought of using the Date as a String but then it would make the verification very difficult.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
just pass the parameters in the correct order, like this:
new Date(day, monthIndex, year);
I wasn't using the 'momentsjs' correctly, first i needed to parse the input date by using
let formatedDate = moment(this.date,"DD-MM-YYYY");
and then for displaying the date i should have used
let fixedDate = moment(this.registers.date).format("DD/MM/YYYY");

Issue with passing a value to Date Object

I am want to display a date in MM/yyyy format. I am using the below code to change the format :
var inputDate = new Date(data);
var date = dojo.date.locale.format(inputDate, {datePattern: "MM/yyyy", selector: "date"});
data contains the input date. For example when German Locale is set in the browser, the input value is like : 01.03.2016 05:30
while creating the date object with this value gives invalid Date though it works when the US locale is set in the browser.Please guide to fix this.
You can use locale.parse to convert your localized date string into a date object, then convert the date object into the formatted date you want.
See this small example:
var browserLocale = 'de',
data = '01.03.2016 05:30';
require(["dojo/i18n", "dojo/date/locale"], function(i18n, locale){
require([i18n.getL10nName("dojo/cldr", "gregorian", browserLocale)], function() {
var dateObject = locale.parse(data, {formatLength: 'short', locale: 'de'});
alert(locale.format(dateObject, {datePattern: "MM/yyyy", selector: "date"}));
});
});
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>