How to save date into database with current time? - sql

I have a table in database, one of the row adds add while something was done/acomplished. And it works fine. But.. it doesn't add current time. When I prints out date from db, it shows 2016-12-13 00:00. Instead of for example 2016-12-13 15:32. How do I add current time?
This is how my sql looks
[example_date] DATE NOT NULL,

The date data type does not have a time component. You want either datetime or datetime2 (or perhaps smalldatetime):
example_datetime DATETIME NOT NULL,
You can review the documentation for the various date/time data types here.

Related

Odoo sequence reset insist using UTC

I am using Odoo sequence for a form number. This sequence is set to reset every month. But I have noticed an issue in the sequence reset time.
The sequence turns out resetting every UTC not at server timezone which is UTC +8. So when a transaction happened at 1 July 7 AM (UTC + 8) the sequence is still not being reset. The reset happened on 1 July at 8 AM (UTC).
How can I make the sequence reset based on my timezone? The server timezone is already UTC + 8.
Two Options:
Check the timezone of your database. Do this in your postgres db terminal with the command:
show timezone;
You should expect your local timezone or UTC
If you check the model behind the feature, in the postgress console:
\d ir_sequence_date_range
You may notice that the fields related to the range of the dates (date_from, date_to) were created as "date" and not "datetime" so it gonna miss the hours.
Also, in the form view, the is not possible to set the time:
sequence_form
So an alternative is change the data type of the column from date to datetime. To do this you must extend the model and over write the field something like this:
class IrSequenceDateRangeExtended(models.Model):
_inherit = 'ir.sequence.date_range'
date_from = fields.Datetime(string='From', required=True)
date_to = fields.Datetime(string='To', required=True)
Then, after update you should be able to set the time to the date.
I hope it helps you.

The datetime type is not retained when the query result is saved as csv

I am using the following query to fetch some results from a bigquery dataset:
SELECT name, TIMESTAMP(due) AS due, TIMESTAMP(start) AS start,
FROM myBigQueryTable
Then, I save the query result as csv. However, the due and start columns do not have datetime type in the csv file and displays a value like:
1.41E+09
instead of this:
2014-12-24 00:00:00 UTC
If I only use DATE instead of TIMESTAMP then the problem disappears, however I also need the time info. How can I resolve this issue?
This is a known problem with BigQuery UI and it is tracked here: https://issuetracker.google.com/issues/36614760.
I have the fix ready and it will go out into production within few weeks.

SSAS 2014, relation to time dimension using YYYYMM field. Best practice?

In the process of creating a new cube for my client, I encountered a problem I'm not sure hot to deal with.
I have a table that doesn't have a DateTime field; instead it has a varchar field which contains year and month in YYYYMM format. I need to create a relation to my Time dimension using that field; and proceed with creating Year-Quarter_Month hierarchy.
First thing I did was creating a new named calculation in Time table from the date field to match the YYYYMM format. Now, I understand that the relation can't be created because it would break the referential integrity.
My idea is to create a new Time table/dimension and delete all records except the first day of the month, create a YYYYMM named calculation and then I would be able to create a relation between my table and that new Time table. But, is this the right approach and what downsides I can expect?
Thank you!
You don't need a separate time dimension...when connecting the new fact table to the existing time dimension (in the dimension usage tab) you can set the YYYYMM attribute as the "granularity attribute"...SSAS will handle the rest :-)
Also, if the format is YYYYMM (ie. 201504 for april 2015) then you might consider making it an integer (instead of a varchar) to save some space in your fact table.
You can create a new calculated column in that table to add the first day of the month:
convert(date, YYYYMMfield*1000+01)
and then link it with your key in your time dimension.
This way, your YYYY-QQ-MM hierarchy levels work as intended, if the user is going deeper and wants to see monthly values on a daily basis, he will find all values for that month added to the first day.

Generic TimeZone According to login user location

I want that all DateTime Objects come from Model may converted to Local of login user. All Datetime are stored in UTC format in Database.
For Example
If someone Create user and CreatedDate is stored in UTC.Now(2014-05-06 01:00PM);
Then someone login from Pakistan and navigate to users view then the DateTime must show as 2014-05-06 06:00PM for last created user.
I know how to convert but which is the best approach to do it. I want to convert all datetime coming from Database into current ..
I saved all My date formats in DateTime.UtcNow
and add 1 column TimeZoneId in DB and check it whenever some results are need to be shown on view or any thing want to manipulate according to timezone of current user.

how to insert current time automatically in table in oracle forms?

I have a problem in oracle forms.
My database is consisting of a main table,table name is (buy_order_customer) which has (b_order_id,customer_id,b_date,b_time).
I'd like to insert the current time automatically in the b_time column, I'm able to insert the current date in the b_date column but I can't do the same with b_time.
Both b_date, and b_time is of type 'date'.
can any one help please?
thanks in advance.
In Oracle DB a DATE datatype always contain both date and time (even if you don't display them.
So, if you inserted the current date into b_date then you already have the current time as well.
Try this:
SELECT to_char(b_date, 'mm-dd-yyyy hh24:mi:ss')
FROM buy_order_customer
and see that you have the time as well
I think you mean the initialvalue to fill these fields in a form at runtime.
If I'm right then you need one of the following system variables:
$$DATE$$ retrieves the current operating system date (client-side).
$$DATETIME$$ retrieves the current operating system date and time.
$$DBDATE$$ retrieves the current database date.
$$DBDATETIME$$ retrieves the current date and time from the local database.
I don't know any system variable to retrieve only the time.
If it is for displaying purposes you need to use dateformat masks on your fields.