Desktop version

Main > Forum > 1C:Enterprise Platform > 1C:Enterprise – Business applications platform > Wrong parameter DATETIME

Forum

Search UsersRules
Wrong parameter DATETIME
#1
Active user
Points:: 0
Joined:: Apr 2, 2025

Why following query gives "Wrong parameter" error?


Code
SELECT
   DATETIME(YEAR(&Period), MONTH(&Period), 7) AS MyCustomDate
INTO DatesRawData

Profile
#2
Administrator
Points:: 0
Joined:: Oct 3, 2019

This construct will not work! The 1C query language is not a full SQL language, and of course it has its limitations… For example, the DATETIME function only works when numeric parameters are passed to it. And although the result of the YEAR function is also of type Number, DATETIME still does not accept it…

In your case, you can do it differently:

Code
SELECT
   DATEADD(BEGINOFPERIOD(&Period, MONTH), DAY, 7) AS FIELD

Profile
#3
Active user
Points:: 0
Joined:: Apr 2, 2025

Well, I wanted to generate all days of a given date, "&Period".

If "&Period" is 2025-12-17 then I must generate

2025-12-1
2025-12-2
2025-12-3
...
2025-12-31

I did following query

[CODE][/CODE]

(I can't continue editing this post of mine. I am frequently getting "Access denied" error at this site)

Profile
#4
Administrator
Points:: 0
Joined:: Oct 3, 2019

Hello Bahrom,

could you please clarify: is this for a learning exercise or for a real work project?

The reason I ask is that due to the limitations of the query language in 1C, it's sometimes easier to perform certain operations directly in 1C code rather than within a query.

I'll try to help you either way, but please keep this in mind :-)

Profile
#5
Active user
Points:: 0
Joined:: Apr 2, 2025

Bro, It is for a real very very serious work project.

Profile
#6
Administrator
Points:: 0
Joined:: Oct 3, 2019

If we need to generate all the days of a month using only a query, we can do it like this:

1. Create a set of numbers from 0 to 30
2. Add them to the first day of the month
3. Trim off dates that fall outside the month

The query text will look something like this:

Code
SELECT
   DATEADD(BEGINOFPERIOD(&Period, MONTH), DAY, Numbers.DayOffset) AS DayDate
FROM
   (SELECT 0 AS DayOffset
   UNION ALL SELECT 1
   UNION ALL SELECT 2
   UNION ALL SELECT 3
   UNION ALL SELECT 4
   UNION ALL SELECT 5
   UNION ALL SELECT 6
   UNION ALL SELECT 7
   UNION ALL SELECT 8
   UNION ALL SELECT 9
   UNION ALL SELECT 10
   UNION ALL SELECT 11
   UNION ALL SELECT 12
   UNION ALL SELECT 13
   UNION ALL SELECT 14
   UNION ALL SELECT 15
   UNION ALL SELECT 16
   UNION ALL SELECT 17
   UNION ALL SELECT 18
   UNION ALL SELECT 19
   UNION ALL SELECT 20
   UNION ALL SELECT 21
   UNION ALL SELECT 22
   UNION ALL SELECT 23
   UNION ALL SELECT 24
   UNION ALL SELECT 25
   UNION ALL SELECT 26
   UNION ALL SELECT 27
   UNION ALL SELECT 28
   UNION ALL SELECT 29
   UNION ALL SELECT 30) AS Numbers
WHERE
   DATEADD(BEGINOFPERIOD(&Period, MONTH), DAY, Numbers.DayOffset) <= ENDOFPERIOD(&Period, MONTH)
ORDER BY
   DayDate

Profile
#7
Active user
Points:: 0
Joined:: Apr 2, 2025

Oh, thank you. I forgot to tell you that I already did it in exactly this way, using

Code
UNION ALL
.

Many thanks for your reply

Profile
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)



© 1C LLC. All rights reserved
1C Company respects the privacy of our customers and visitors
to our Web-site.