sqldatetime

Calculate start date of almost equal periods

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-29 17:22:55
问题 SQL Server CREATE TABLE [TABLE_1] ( PLAN_NR decimal(28,6) NULL, START_DATE datetime NULL, MAX_PERIODS decimal(28,6) NULL, ); INSERT INTO TABLE_1 (PLAN_NR, START_DATE, MAX_PERIODS) VALUES (1, '2020-05-01', 8), (2, '2020-08-01', 8); SQL - FIDDLE I've got a table with the columns PLAN_NR , START_DATE and MAX_PERIODS . Each period is exactly 7 days long, unless the period contains a month end. Then the period should be divided into a range before the end of the month up to and including the last

SQL Server - Round TIME values to the next minute

假装没事ソ 提交于 2020-04-13 05:54:10
问题 I've found many posts about rounding "down" time values (e.g. https://stackoverflow.com/a/6667041/468823), but I have another problem: I wanna round to the higher minute and not to the lower, how can I do? My code: SELECT PA.ORE AS TOT_HOURS, CAST(CAST(PA.ORA_INIZIO AS DATETIME) AS TIME) AS BEGIN_TIME, CAST(dateadd(minute, datediff(minute, 0, (CAST(PA.ORA_INIZIO AS DATETIME))), 0) AS TIME) AS BEGIN_TIME_ROUNDED FROM PRG_ATTIVITA PA INNER JOIN PRG_TIPI_ATTIVITA PTA ON PA.ID_TIPO_ATTIVITA = PTA

How to convert time which is in GPS format to Local time format in SQL?

主宰稳场 提交于 2020-02-04 14:33:18
问题 This is the data packet which was received from android mobile to my server. $|351746051743568|12.9399604|77.6257631|0.0|1392979784822|1|# In which following is the time which is received from the device: 1392979784822. Since this is in GPS format, I tried to convert into local format in SQL and failed. Please guide me in this issue. 回答1: Looks like unix/epoch time in millisecs? declare @x bigint = 1392979784822 declare @msin1day bigint = 3600 * 24 * 1000 select dateadd(ms, @x % @msin1day,

Getting SqlDateTime overflow. exception in 2008

醉酒当歌 提交于 2020-01-16 19:42:19
问题 am passing default dates (startdate & enddate) to an sp as ('1/1/1753 12:00:00 AM' & '12/31/9999 12:00:00 AM'). This was working fine in 2005, but am getting "SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM" exception in 2008. And the twist is such that when i run the sp from Management studio it works fine but on the live server through website it gives error. thanks in advance 回答1: I'd agree with Ed Harper that the problem is likely to be locale or

Getting SqlDateTime overflow. exception in 2008

我们两清 提交于 2020-01-16 19:42:01
问题 am passing default dates (startdate & enddate) to an sp as ('1/1/1753 12:00:00 AM' & '12/31/9999 12:00:00 AM'). This was working fine in 2005, but am getting "SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM" exception in 2008. And the twist is such that when i run the sp from Management studio it works fine but on the live server through website it gives error. thanks in advance 回答1: I'd agree with Ed Harper that the problem is likely to be locale or

Select distinct where date is max

家住魔仙堡 提交于 2020-01-06 04:03:27
问题 This feels really stupid to ask, but i can't do this selection in SQL Server Compact (CE) If i have two tables like this: Statuses Users id | status | thedate id | name ------------------------- ----------------------- 0 | Single | 2014-01-01 0 | Lisa 0 | Engaged | 2014-01-02 1 | John 1 | Single | 2014-01-03 0 | Divorced | 2014-01-04 How can i now select the latest status for each person in statuses? the result should be: Id | Name | Date | Status -------------------------------- 0 | Lisa |

how to convert date into month number?

青春壹個敷衍的年華 提交于 2019-12-31 01:54:06
问题 I have a column Month in my table. The month name and date are stored in this month column like Month 01-JAN-12 02-FEB-12 and so on. How do I convert the DATE into month number such as Month 1 2 etc. 回答1: select to_char(to_date('01-JAN-12','dd-mon-yy'),'mm') from dual; 回答2: Extract works perfectly for this EXTRACT extracts and returns the value of a specified datetime field with fullYear as( select (to_date('01-jan-12') + 29*level) dte from dual connect by level <= 12 ) select extract(month

Convert a Text to a DateTime in access

风流意气都作罢 提交于 2019-12-25 03:47:45
问题 So i have a field that datatype is a text which is feed into the database. What it returns is something along the lines of this: ddd MMM dd hh:mm:ss yyyy What i would like for it to do is be displayed as something like this: ddd MMM dd yyyy hh:mm:ss I can achive this by using Format() which would look like this: Format(alarmdet.AlarmStart, "ddd MMM dd yyyy hh:mm:ss) AS AlarmDateTime So that is all well and good, however; i want to beable to convert this value into a datetime. I've tried using

Servlet get date and time

孤人 提交于 2019-12-24 17:50:14
问题 I'm using the following code to get the date and time public class offer extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { out.println("<html>"); out.println("<head>"); out.println("<title>Servlet offer</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1> sv sugar mills</h1>"

How to convert LocalDate to SQL Date Java?

醉酒当歌 提交于 2019-12-17 07:15:45
问题 How do I convert a LocalDate to a java.sql.Date ? Attempt: Record r = new Record(); LocalDate date = new Date(1967, 06, 22); r.setDateOfBirth(new Date(date)); This fails (won't compile) and all I can find is Joda time stuff. I'm using Java 8 回答1: The answer is really simple; import java.sql.Date; ... LocalDate locald = LocalDate.of(1967, 06, 22); Date date = Date.valueOf(locald); // Magic happens here! r.setDateOfBirth(date); If you would want to convert it the other way around, you do it