0

i have a particular case of a task that was assigned to me like a week ago and i'm stuck on it.

last week i was told that i have to make that i need to make a search that finds all rows inserted in a determined month of a particular year, let's say i need to return all rows inserted in november of 2019 not specifying the day, that is fine to that point, the tricky part is that usually the database i work on have the dates converted to number, resulting in dates stored something like this "43275" because of the numeric conversión so it makes difficult to search data because it won't match unless it is converted as well.

i tried a couple of methods such as format date time, converting by cdate(most accurate 'till now) but none has done the job, the cdate converts the data to date, but adds the first day making it useless as well, here is a portion of the code i'm trying

numero_mes = request.item("numero_mes")
numero_anio = request.item("numero_anio")
fecha_buscador_cip = cDate(numero_mes &"-"& numero_anio)
buscar_fecha = clng(fecha_buscador_cip)

the result of that code is a conversion similar to what i need but not exactly since the converted date varies since there is a specific date, how can i do the task i'm assigned? i can't find a way yet to do this, any kind of help would be great, thanks in advance.

2
  • 1
    What date is "43275"? Can you post the formula that converts a date to a number like that one? Nov 15, 2019 at 18:23
  • 1
    Assuming 43275 is the number of days since January 1, 1900, you could easily determine the date using VBScript's DateAdd function. Conversely, you could convert any VBScript date to the number of days since January 1, 1900 using VBScript's DateDiff function. For example, getDate = DateAdd("d", 43275, "1/1/1900") and getNum = DateDiff("d", "1/1/1900", "November 11, 2019"). Hope this helps.
    – leeharvey1
    Nov 17, 2019 at 15:13

1 Answer 1

2

Calculate November 1 and 30 as numbers, and then find all numbers between (and including) those two.

I don’t know your conversion, but let’s say Nov 1 converts to 42501 and Nov 30 is 42530. Do a query for all records WHERE date >= 42501 AND date <= 42530

3
  • 1
    hi Stephen, you mean i can't remove the days from the date but instead i have to select them all in order to extract all the information inserted in a month?
    – RUCK FULES
    Nov 15, 2019 at 18:18
  • 1
    Use the formula that generates the numbers that are in the database to convert 11/1 and 11/30 to numbers like the ones in your database. Then use those numbers to filter the data. Nov 15, 2019 at 18:22
  • 1
    thank you @StephenR your answer guided me to the success, you see i made a counter from 1 to X depending on the case of the month requested and then converted the date to number, that way it executes multiple times the query, obtaining the entire month, and yes, the example you used nailed the truth, the resulting number of converting a date to number is the equivalent number of days from 30-12-1899 (day 0) so it became much easier to read that date, thank you sooooo much :D
    – RUCK FULES
    Nov 20, 2019 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.