This question already has answers here:
SQL Server Convert a number
(2 answers)
Closed 8 years ago.
I have this number format (I have it as varchar in my table) 6.71307E+15 I want to convert it to this: 6713073544159400.
Is there a way I can do that in SQL Server, because currently I have to do it manually using Excel.
This should give you the closest representation:
SELECT CONVERT(BIGINT, CONVERT(FLOAT, '6.71307E+15'));
Even excel should only result 6713070000000000
Related
This question already has an answer here:
Format current date and time in VBScript
(1 answer)
Closed 4 years ago.
I am working in a classic asp project where I am selecting an SQL query from the database. The query was working fine in my own laptop and the date format is '11/14/2018' from this query but it's giving the mentioned error in office system and when I checked the query in SSMS then it's generating the date format as '14-11-2018'. I tried changing the different VB date formats but the result was same.
Here is the query:
sql="select count(*) as total from hc_query a, hc_breakup b where a.querytype='hotel' and a.qdate='" & FormatDateTime(Now(),vbShortDate) & "' and a.t_id=b.pnrno and b.bookstatus='half'" '
Please give some suggestions. Thanks
The problem is not in the code but in the assumptions about the function's output. The documentation for FormatDateTime states about the NamedFormat argument:
vbShortDate : 2
Display a date using the short date format specified in your
computer's regional settings.
That is, the output format depends on local configuration of the computer running the code. Two different computers can generate different output depending on locale configuration.
If you need a consistent output to deal with dates stored as strings in database fields, then you will need to write your own function to ensure consistency.
This question already has answers here:
SQL cast datetime
(3 answers)
Closed 5 years ago.
Running a simple T-SQL query of SELECT CONVERT(date, '') will render a result of 1900-01-01. It seems to me that it would be more consistent to convert a blank string to either 1753-01-01 (the minimum allowable date value) or NULL. 1900 just seems so arbitrary, but I assume this was a deliberate design choice made by the MS SQL programmers. What is the purpose of this functionality?
It is due to implicit conversion. The 0 date in sql server is 1/1/1900. Any dates earlier than that are a negative number.
SQL Server datetime calendar start point is start of day of 01 January 1900.
https://stackoverflow.com/a/17071583/7974050
This question already has answers here:
Best approach to remove time part of datetime in SQL Server
(23 answers)
Closed 5 years ago.
I was wondering if anyone new how to remove the time hh,mm,ss from the getdate? I am very new to using SQL and am having trouble. Right now I have the date added so it could always pull the current date and add one day to that. Now I need to remove the time from being shown completely. I do NOT want to change time to 00:00:00, I want it to be completely hidden.
Here is my code:
Select DATEADD(DAY, 1, GETDATE())
Use CAST or CONVERT.
Using CAST
SELECT DATEADD(DAY,1,CAST(GETDATE() as date))
Using CONVERT
SELECT DATEADD(DAY,1,CONVERT(date,GETDATE()))
This question already has answers here:
PHP Date Formatting not working wen using date_format()
(2 answers)
Closed 6 years ago.
I try to create datetime form dd/mm/yy(yy), but with no success?
code:
var_dump(date_create("22/12/2016"));
or
var_dump(strtotime("22/12/2016"));
neither works. This is the demo. Why I cannot create from this format?
before date_create convert your date into an acceptable date format
using
DateTime::createFromFormat
(PHP 5 >= 5.3.0, PHP 7)
DateTime::createFromFormat -- date_create_from_format — Parses a time string according to a specified format
var_dump(date_create(DateTime::createFromFormat('d/m/Y', "22/12/2016")->format('Y-m-d')));
Demo
This question already has an answer here:
Using DateTime?.Value.TimeOfDay in LINQ Query
(1 answer)
Closed 8 years ago.
I'm storing a time span in Sql Server as two columns of type datetime. (start and end)
So the date part of each column needs to be ignored.
Given some c# datetime instance, using an EF linq query, how can I determine whether the c# datetime's time is within the time span?
So the date part of all three values is ignored.
You can extract TimeOfDay property from DateTime that gives you the TimeSpan representing the time into the day:
DateTime dt = DateTime.Now;
dt.TimeOfDay;
Returns TimeSpan :
14:16:22.3100098