I see a new data typeDATE being introduced in the BigQuery Web UI but not documented in https://cloud.google.com/bigquery/data-types.
Well DATE as such is not new but I have one major question. Unlike TIMESTAMP does DATE ignore timezone information after being stored.
Quoted text from TIMESTAMP documentation:
You can supply a timezone offset in your date and time strings, but
BigQuery doesn't preserve the offset after converting the value to its
internal format. If you need to preserve the original timezone data,
store the timezone offset in a separate column.
Also whats the expected input for this format. I have tried the known timestamp strings but it does not seem to work.
I see a new data typeDATE being introduced in the BigQuery Web UI but
not documented
Date type was introduced with Standard SQL - see Date type for details
Also whats the expected input for this format
Canonical format
'YYYY-[M]M-[D]D'
YYYY: Four-digit year
[M]M: One or two digit month
[D]D: One or two digit day
Note: The DATE type represents a logical calendar date, independent of time zone.
Related
Lets say I have a table Student with columns Name,DOJ,TOJ.
Inorder to enter date in mm/dd/yyyy format and timestamp in the format hh24:mm:ss I used ALTER SESSION SET NLS_DATE_FORMAT='MM/DD/YYYY' and ALTER NLS_TIMESTAMP_FORMAT='HH24:MI:SS' but i want to know an alternative solution to enter in this format without involving session. Please guide me through this.
CLICK HERE TO VIEW COLUMNS AND THEIR DATA TYPES
We store dates/times either in a DATE column (which is Oracle's inappropriate name for a datetime) or a TIMESTAMP column (which has more precision and can handle timezones, too). These types have no format. This is important, because thus comparing and sorting them in the database works fine, because the DBMS knows how to handle datetimes, while the users see the date in their format. I, for instance, have set my Windows to German, so I will see the datetimes in some German format, while you will see the same date in a format you are used to.
There are few situations where you want to store date and time separately. The reason is typically that you can set them null. A date without a time means "the whole day". A time without a date means "every day this time". But then you often want this even more advanced anyway ("every Tuesday and Wednesday", "every December 24", etc.) for which you need soemthing more sophisticated then just date and time split into two.
So, usually we just store date and time combined. For a precision down to seconds we use DATE. If we wanted them separately we'd have to think of an appropriate data type, because Oracle has no real date type and no time type either. So we'd either use DATE and ignore the date part or the time part or we use strings. The former solution is usually preferred, because you cannot mistakenly enter invalid data like February 30 or 23:66:00.
If you want to store formatted dates and times, you are talking about strings. I don't recommend this. Strings are not the appropriate data types for dates and times. And a format '01/02/2000' is ambiguous. Some people will read this as February 1, others as January 2.
If you wanted to do this, you would have to change the column types to VARCHAR2 and simply store values like '02/25/2021' and '13:28:56'.
But if you wanted to sort your data or compare dates/times then or just show them to a foreign user in a format they are used to, you would always have to convert them. E.g.:
select *
from mytable
order by to_date(doj || ' ' || toj, 'mm/dd/yyyy hh24:mi:ss');
I am afraid that to change default format you have no other option but to change NLS_DATE_FORMAT either in database level or session level.
But If your purpose is to show the date in a specific format in the front end then you can use to_char() function as below:
SELECT NAME, to_CHAR(DOJ,'dd/mm/yyyy'),to_CHAR(TOJ,'HH24:MI:SS') FROM table
To change the default date format in system level:
ALTER SYSTEM SET NLS_DATE_FORMAT='DD/MM/YYYY' scope=both;
You can also change the default date format at startup time with a login trigger to change the nls_date_format:
CREATE OR REPLACE TRIGGER CHANGE_DATE_FORMAT
AFTER LOGON ON DATABASE
call DBMS_SESSION.SET_NLS('NLS_DATE_FORMAT','YYYYMMDD');
In Mosaic Decisions Flows, I can see there's a system parameter called "$currentTime" which gives the current timestamp. But this is giving the current timestamp in UTC. I want to convert it into CST timezone. Is there a way I can do that?
Yes, you can use Convert_Timezone function available in transformation node. Below is the syntax for it.
CONVERT_TIMEZONE( column_name, ‘Timezone1’ , ‘Timezone2’);
Column_name – input time based column.
Timezone1 – the timezone the column data is in.
Timezone2 – the timezone in which the column data has to be converted in.
CONVERT_TIMEZONE (NOW(), ‘UTC’ , ‘CST6CDT’ ) -> NOW() will give you the currentTime
Similarly you can use – SystemV/CST6CDT, SystemV/CST6, based on the requirement.
Also you can refer Transformation section in user guide for further details on it [link below] :
https://mosaic.ga.lti-mosaic.com/usermanual/Transformer.html
I am designing a database for use with a Ruby on Rails application. For a given object, I need to access the date of an event in both the Gregorian format and the Hebrew calendar equivalent. I can easily convert between the two formats, but the issue is that in the Hebrew calendar, the date changes at sunset, not midnight. Therefore, I'll need to either store two separate dates, or store a Gregorian date and a separate boolean field, after_sunset. Then, whenever I need to access the Hebrew date, I'll need to query for both fields, convert the date, and if after_sunset==true, increment the date.
Which of these options is considered "better"?
And, if I store the Hebrew date separately, is it best to store it as a String, an Integer, or can I use a regular Date?
With an after_sunset flag you store a Gregorian date and add all the additional information needed to know the Hebrew date.
With two dates you would store the two dates explicitely. However, to have data consistent you would install a check constraint to ensure that the dates match. This is because the two dates share part of their information (redundancy). This means the data is not normalized.
For this reason, to have data normalized in your database (and thus not having to install a check constraint to keep the data consistent) the first approach is better. Store the date plus an after- sunset flag.
Store the date in UTC and also store in unix format
You can use conversion function based on the type
This will allow your database to support other date time formats easily in the future
Unless you are going back to the dawn of time, I think I would simply have a many-year lookup table of UTC datetimes and Hebrew dates where the UTC column is the first second of the Hebrew day in a specific time zone (Greenwich?).
Conversions are a quick binary search,
SELECT hebrew_date FROM hebrew_gregorian_lookup
WHERE some_input_time >= gregorian_cutoff
ORDER BY gregorian_cutoff DESC LIMIT 1;
If you index and cluster the lookup table on gregorian_cutoff, it should be very quick, even for 100 years. (If your RDBMS has a way to force a table into RAM, even better.) Also depending on your RDBMS, you may be able to wrap this in a function/procedure with no loss of efficiency.
I suggest storing the Hebrew date not as a string but as a record of three shorts, day, month, year. You can have a tiny lookup table for month to string, or perhaps use an enumeration. That will give you some flexibility in formatting, e.g., Hebrew characters vs. Latin in the output.
Is there a date or datetime data type in Google BigQuery? I looked at the online documentation, but the data types mentioned didn't include any date types
2013 update:
BigQuery now has a Timestamp type.
Look at: BigQuery datatypes
2018: TIMESTAMP, TIME, DATE, DATETIME
2016 update:
BigQuery now also has real DATE type (in addition to TIMESTAMP type) in standard SQL:
https://cloud.google.com/bigquery/sql-reference/data-types#date-type
https://cloud.google.com/bigquery/sql-reference/functions-and-operators#date
Edited to add: There is a date time type, see Fh's answer for more information.
No date data type is available, although if you use ISO-formatted date-times (YYYY-MM-DD HH:MM:SS[.uuuuuu]) or timestamps (convertable to microseconds since 1970) there are a number of date functions that you can use. See this page for more information.
How do I use an SQL statement on an sqllite database to insert the current date in UTC. I found the NOW function but what format is that in? This will be on mobile devices so everyone will have a different locale, however, I need a standard time format because the device will compare the dates with my server.
Also, is there a way to automatically update a 'modified' field when the data in the row is changed like you can in MySQL?
SELECT DATETIME('now') returns the current UTC datetime. See Date And Time Functions. You can use DATETIME DEFAULT CURRENT_TIMESTAMP with column declaration.
Format 11, the string 'now', is
converted into the current date and
time as obtained from the xCurrentTime
method of the sqlite3_vfs object in
use. Universal Coordinated Time (UTC)
is used
For the 'modified' field you can use a trigger.
You don't specify what you use to develop your application on. I prefer using QDate::toJulianDay and QDate::fromJulianDay in Qt to store dates in an SQLite database as an integer if I only need to store the date.