MS SQL Server - convert(datetime, string, code) -> What code for dd/mm/yyyy hh:mm:ss (24hours)? - sql

I would to CONVERT this string 08/12/2014 16:46:12 to a datetime but I do not know what code to use and it is driving me crazy. I looked on many pages but do not find it
CONVERT(datetime,'08/12/2014 16:46:12',???)
Thank you in advance

Parameter 131 is incorrect, because it uses the Hijri calendar - 2014 becomes 2576.
Use 103 as style parameter instead:
convert(datetime,'08/12/2014 16:46:12',103)
Despite the documentation on http://www.w3schools.com/sql/func_convert.asp it also converts the time value (tested on SQL Server 2014 and 2008 Express).

convert(datetime,'08/12/2014 16:46:12',13)
OR
convert(datetime,'08/12/2014 16:46:12',113)
One Last GO :)
SELECT CONCAT ((convert(datetime,'08/12/2014,103)),' ',(convert(datetime,'16:46:12',114))) AS DateTime
Here is a list of them all http://www.w3schools.com/sql/func_convert.asp

Related

Convert Integer to Date in Snowflake using Error Handling

I have a requirement where integer value should be converted to date type in Snowflake.Initially I used following query to get the desired result:
SELECT TO_DATE(TO_varchar(19000000+1200034),'YYYYMMDD')
2019-07-09
Now when I used same query for the input - "20200034", I am getting following error:
select TO_DATE(TO_varchar(19000000+1200034),'YYYYMMDD')
Can't parse '20200034' as date with format 'YYYYMMDD'
"20200034" is actually coming from one of the columns in snowflake table. To resolve this issue I tried using "TRY_TO_DATE" function, but output of "TRY_TO_DATE" function is giving incorrect result. Please find details below:
select TRY_TO_DATE(TO_varchar(19000000+1200034))
1970-08-22
As per Snowflake documentation, error handling function does not support optional format argument supported by TO_DATE , DATE.
https://docs.snowflake.com/en/sql-reference/functions/try_to_date.html
You can set the DATE_INPUT_FORMAT for the session before calling the TRY_TO_DATE function.
I suggest you contact Snowflake support and ask them to enable try_to_date with format string - it's available but needs to be enabled manually.
However you have to be aware that TRY_TO_DATE on '20200034' will be resolved to NULL.

how to add days in orient db

How do we add days to dates in Orient db?
select sysdate()+1 from safetyplan;
It is giving same output as sysdate().
1 is not getting added. Can you help me, please?
According to Orientdb doc 2.2:
sysdate() returns the current date time. If executed with no parameters, it
returns a Date object, otherwise a string with the requested
format/timezone.
So one possible way is to convert date object to long using .asLong() method of date object.Then do the necessary addition.Convert it back to date using .asDate() method.
Example:To get a day added to current day use:
select sum(sysdate().asLong(),86400000).asDate() from safetyplan;
Note:we are adding in milliseconds and 1 day=1000*60*60*24 milliseconds
NB:Thought that this answers may help someone and sorry for answering my own question.

How to Show date in textbox which type is date in asp.net

How to Show date in textbox from database.TextBox type is "date". In asp.net
As the experts said above, this one worked for me:
((DateTime)dr["columnName"]).ToString("yyyy-MM-dd")
or
Convert.ToDateTime(dr["columnName"]).ToString("yyyy-MM-dd");
Try to re-format the date in the parentheses, it may be (yyyy-MM-dd) or (dd-MM-yyyy)
This one is working in 2023.
NOTE: I'm fetching the data from the database in a DataRow instead of DataTable, NOT because it works better, but because this is what I need.
You need to convert the value to a datetime, then convert again to string.
Something like this:
_txtCoatOrderDate.Text = ((Datetime)dt.Rows[i]["Coat_CUSTM_Date"]).ToString("dd/MM/yyyy");
Try this-
_txtCoatOrderDate.Text = Convert.ToDateTime(dt.Rows[i]["Coat_CUSTM_Date"]).ToString("dd/MM/yyyy");
i tried this its working
TextBox1.Text = ((DateTime)ds.Tables[0].Rows[0]["Coat_CUSTM_Date"]).ToString("yyyy-MM-dd");
Thanks RMH Sir

Splunk date comparison

I need to be able to search for log entries with a specific start date, which has nothing to do with _time. The format is, for example, Start_Date: 08/26/2013 4:30 PM.
I need to add a condition in my search to specify the date, but not the time. I tried strptime and strftime unsuccessfully.
For example, I tried converting start date to a string (without time) and compare it to another string:
"08/26/2013"=strftime(Start_Date, "%d/%m/%Y")
This didn't work either:
"08/26/2013"=strftime(strptime(Start_Date "%d/%m/%Y %I:%M %p"), "%d/%m/%Y")
Any ideas how to solve this?
A * did the trick: Start_Date=08/26/2013*
Answer here: http://answers.splunk.com/answers/100630/splunk-date-comparison

Convert a cell to TimeStamp w Time zone as parameter for SQL Query in Excel 2007

so my query has
where date_trunc('DAY', mh.end) > ?
However when I try to put stuff like "3/31/2012 12:00:00 AM" or "2012-01-31" in the cell, it complains about it not being Timestamp with TIMEZONE format. How can I get it to accept the date? I have been trying to search but I have not found other people having this problem (my search terms might have been off).
Ok I figured it out. I had to convert the date to Text using =TEXT(B1,"yyyy-mm-dd hh:mm:ss") After that it works fine