I am facing an issue with the time conversion.
Whenever I tried to change the time to timestamp. It does not work.
I have tried many of functions from http://docs.amazonaws.cn/en_us/redshift/latest/dg/Date_functions_header.html
But still a single function did not convert the date time to timestamp. An eg. I need date time (2017-12-11 23:38:11) as timestamp (1513036800) format.
Can you please guys tell me the exact function to convert that?
Also I have tried to use CONVERT_TIMEZONE function.
It works fine, whenever I passed the static date inside this like: CONVERT_TIMEZONE('GMT','GMT -1','2017-12-11 23:38:11')
But if I change the date with my variable name, I am getting an error message:
"ERROR: function convert_timezone("unknown", "unknown", character varying) does not exist HINT: No function matches the given name and argument types. You may need to add explicit type casts."
Can you guys tell me function to convert the date into timestamp?
Can you guys tell me reason of the above error while passing the dynamic variable?
I want to add timezone and date together and then to get the timestamp value of that, is that possible?
Dateadd function gives the same error while passing the dynamic variable.
Per error message it looks like your timestamp is stored in a varchar column. You have to change the column to timestamp or convert the value on the fly to be able to use timestamp functions. I suggest the first because it has better performance. Redshift doesn't support column data type alteration, so to do this you have to recreate the table DDL with timestamp data type for time columns, insert data to the new table and replace the old table with it.
As for dynamic conversion, it's like this:
EXTRACT('epoch' FROM CONVERT_TIMEZONE('GMT','GMT -1',your_column::timestamp))
you just don't need to use ::timestamp part if you convert the column
Related
I have the below Query I am trying to genialize the dates to calculate current quarter in Sienese.
.Am I doing something wrong and what will be the correct way?
I have tried concat(year(current_date()),'Q',quarter(current_date())).It works in dbvisualizer but not in sisense.
The message is indicating a value you are trying to convert to date is null, it is not a matter of how you convert it, it is that null can never be converted to anything. You can review the data and change the conditions of what gets returned to avoid that, or use ISNULL() for error control possibly by specifying a date to use by default..
https://www.w3schools.com/sql/func_sqlserver_isnull.asp
I am using this query to generate a DataTable to display information for users to select from. The fill method I am using gives teh ff error.
Conversion failed when converting date and/or time from character
string
SELECT Time_Slot.TimeSlot, Proposed_Date.Date
FROM Time_Slot CROSS JOIN
Proposed_Date
WHERE (Time_Slot.TimeSlot_ID NOT IN
(SELECT Event_Time_ID
FROM Event_Booking
WHERE (Booking_Date = #Booking_Date)))
DTAvailableBookingsTableAdapter.FillAvailableBookings(DSEventBooking.DTAvailableBookings, MonthCalendar1.SelectionRange.Start.ToShortDateString)
Any help in resolving the error would be welcome
Many people make their own lives difficult when it comes to dates. VB.NET has a dedicated data type for dates so, if you are working with dates, use it. Don't convert anything that is not text to text, unless it is specifically for display/serialisation purposes, where only text is supported.
Presumably your Booking_Date is the appropriate data type for dates in your database, e.g. Date/Time in Access or date in SQL Server. In that case, the #Booking_Date parameter is expecting a value of that type, not text. In that case, why are you converting a value of the correct type to a value of the incorrect type here:
MonthCalendar1.SelectionRange.Start.ToShortDateString
The Start property is the correct type and you spoil it by converting it to a String. Don't. Just pass the DateTime value that you already have because that is what's expected.
MonthCalendar1.SelectionRange.Start
Coming from a MonthCalendar, it should already have the time portion zeroed so there's no need to do that yourself but, in cases where you did need to, you can get the Date property of a DateTime value to get another DateTime value with the same date and the time zeroed.
MonthCalendar1.SelectionRange.Start.Date
Note that DateTime is a .NET type and VB has a Date type that is simply an alias for that, i.e. a Date and a DateTime are the same thing. If this is confusing, it shouldn't be. Int32 is a .NET type too and Integer is a VB data type that maps to it. Do you use Integer all the time without any confusion? If so then you should use Date all the time without confusion too.
I am using Oracle SQL and I would like to insert a time value (eg 15:45 or 15:45:00) into a column which has a data type of TIMESTAMP. I have tried the following but It gives a error about it not being a valid month.
INSERT trainTbl(Dest, trainTime)
VALUES
('Waterloo', '15:00:00');
Would appreciate if someone could put me on the right direction.
Thanks
Oracle's TIMESTAMP data type holds a complete time and date. You cannot use it to store a time only; either store a complete time and date, or use a different data type for your column.
Some options for ways to store the time only are discussed in How to store only time; not date and time?. However, if you're already storing the date in another column, you should probably just store this information together. There is a reason Oracle provides the data types that it does.
I know that it is possible to reformat the DateTime data type of the current date and time by using select convert. However, I havent been able to find a method to reformat an existing column (DateTime data type) to: hh:mm:ss yyyy/mm/dd. Or even better, I would like to reformat it to show time only. I dont want to simply convert to time data type because I am working with a chart that accepts either Date or Date time. But what I really want to display on that specific axis of the chart is time. Is there any way to reformat DateTime to my requirements? Thanks.
SQL Server's convert function can take an optional style argument depending upon the datatype. This is how you can get a datetime converted to a string in a variety of formats. For example, try running:
select convert(varchar(30), getdate(), 108) -- returns hh:mi:ss
You can replace getdate() in this example with a column name as well.
There are many styles available, as shown in the documentation.
Note that you will be returning a varchar, so you may want to sort by the original column's datatype.
You can use SET DATEFORMAT but this will change all DateTime's on your SQL Server. You can do some custom formatting, but it will convert the DateTime into a VarChar, so you won't be able to treat it as a DateTime.
SET DATEFORMAT: http://msdn.microsoft.com/en-us/library/ms189491.aspx
I'm not sure if you will be able to use the format you're asking about, though.
How can I retrieve a record based on a Date property? I'm trying:
WHERE Meetings.[MDate] = '16/12/2011'
which is the format I use but I get :
"Data type mismatch in criteria expression"
Problem solved: It should have been:
WHERE Meetings.[MDate] = 16/12/2011
No quotation marks.
For where clauses use
columnName = #mm/dd/yyyy#
You'll want to use the SQL date format: '#2011-12-16#'
Use the cast to DATETIME function, CDATE(), which will honour the machine's regional settings. That said, it still a good idea to use an unambiguous date format and the ISO 8601 format is a good one.
Also note that Access doesn't have a date data type: its sole temporal data type is DATETIME and, as its name suggests, always has a time element accurate to one second time granule, even if that time happens to be midnight. Therefore, it is a good idea to always include a time value to one second time granule in all DATETIME literals e.g.
WHERE Meetings.MDate = CDATE('2011-12-16 00:00:00');
Another advantage to the above is that the Access UI will not attempt to reformat the DATETIME literal because it is held as a string.