Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11

Discussione: MSSQL DateandTime

  1. #1
    Utente bannato
    Registrato dal
    Nov 2005
    Messaggi
    112

    MSSQL DateandTime

    Ragazzi ho una pagina asp che deve scrivere la data e l'ora in un campo data/ora di un db mssql.

    il campo nel db è "smalldatetime" lenght 4

    inserisco la data e ora con la funzione now() ma ricevo questo errore :

    The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value.


    che devo fare ??

    grazie!

  2. #2
    La funzione Now() ti restituisce una data di questo tipo gg/mm/aaaa hh.mm.ss quindi credo che l'incompatibilità sia in questo.
    Prova a inserire la data nel db così: FormatDateTime(Cdate(Now()),2)
    Anche se non sono sicura x' è da un po' che non la uso, comunque penso che il tuo problema sia questo ma non ho molto tempo a disposizione per fare ulteriori prove e verifiche

  3. #3
    Utente bannato
    Registrato dal
    Nov 2005
    Messaggi
    112
    ho provato , ma quella funzione mi restituisce la data in questo formato
    '08/01/2007'

    e io ho bisogno di salvare anche -ora-min-sec-


    Insert into ..... Values (21,1111,'prova','08/01/2007 10.30.34',-3)

    Microsoft OLE DB Provider for ODBC Drivers error '80040e07'

    [Microsoft][ODBC SQL Server Driver][SQL Server]The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value.



  4. #4
    Mi sa che allora devi cambiare il tipo di campo a datetime

  5. #5
    Utente bannato
    Registrato dal
    Nov 2005
    Messaggi
    112
    lo stesso errore me lo da anche con il campo del db messo a "datetime"

    ... 1111,'prova','08/01/2007 10.44.33',-2)


    The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value

  6. #6
    Utente bannato
    Registrato dal
    Nov 2005
    Messaggi
    112
    ma la cosa strana è che se la query la faccio da una maschera di access funziona!
    il campo del db è "smalldatetime" e lui inserisce correttamente gg/mm/aaaa ore:mm:ss

    se la stessa cosa la faccio da asp mi da errore di conversion type out of range!

    ma che devo fare ?

  7. #7
    Utente bannato
    Registrato dal
    Nov 2005
    Messaggi
    112
    risolto.

    la data la devo scrivere così : aaaa/mm/gg 10:00:00
    insomma nel formato inglese. e tutto va.

    ora mi serve una funzione che converte le date..
    ne avete già una ?




  8. #8
    Utente bannato
    Registrato dal
    Nov 2005
    Messaggi
    112
    Ok raga, prendete nota potrebbe servire anche a voi :

    questa funzione l'ho adattata anche a db mssql e funziona!!! assafà.

    function formatDBDate(argDate,argDB)

    dim tmpdate,tmpdateoutput
    tmpdate = argDate

    select case argDB
    case "mdb"
    tmpdateoutput = "#yyyy-mm-dd h:m:s#"
    case "mysql"
    tmpdateoutput = "'yyyy-mm-dd h:m:s'"
    case "mssql"
    tmpdateoutput = "'yyyy/mm/dd h:m:s'"

    end select

    tmpdateoutput = replace(tmpdateoutput,"dd",right("0" & day(tmpdate),2))
    tmpdateoutput = replace(tmpdateoutput,"mm",right("0" & month(tmpdate),2))
    tmpdateoutput = replace(tmpdateoutput,"yyyy",year(tmpdate))
    tmpdateoutput = replace(tmpdateoutput,"yy",right(year(tmpdate),2))

    tmpdateoutput = replace(tmpdateoutput,"h",right("0" & hour(tmpdate),2))
    tmpdateoutput = replace(tmpdateoutput,"m",right("0" & minute(tmpdate),2))
    tmpdateoutput = replace(tmpdateoutput,"s",right("0" & second(tmpdate),2))

    formatDBDate = tmpdateoutput

    end function


  9. #9
    Originariamente inviato da cuollins
    Ok raga, prendete nota potrebbe servire anche a voi :

    questa funzione l'ho adattata anche a db mssql e funziona!!! assafà.

    function formatDBDate(argDate,argDB)

    dim tmpdate,tmpdateoutput
    tmpdate = argDate

    select case argDB
    case "mdb"
    tmpdateoutput = "#yyyy-mm-dd h:m:s#"
    case "mysql"
    tmpdateoutput = "'yyyy-mm-dd h:m:s'"
    case "mssql"
    tmpdateoutput = "'yyyy/mm/dd h:m:s'"

    end select

    tmpdateoutput = replace(tmpdateoutput,"dd",right("0" & day(tmpdate),2))
    tmpdateoutput = replace(tmpdateoutput,"mm",right("0" & month(tmpdate),2))
    tmpdateoutput = replace(tmpdateoutput,"yyyy",year(tmpdate))
    tmpdateoutput = replace(tmpdateoutput,"yy",right(year(tmpdate),2))

    tmpdateoutput = replace(tmpdateoutput,"h",right("0" & hour(tmpdate),2))
    tmpdateoutput = replace(tmpdateoutput,"m",right("0" & minute(tmpdate),2))
    tmpdateoutput = replace(tmpdateoutput,"s",right("0" & second(tmpdate),2))

    formatDBDate = tmpdateoutput

    end function

    Ciao,

    la tua funzione non funziona sempre con Sql Server :

    prova nel Query Analizer :

    set language 'us_english' -- OK
    select day('2007/01/08 00:00:00') as gg, month('2007/01/08 00:00:00') as mm

    go

    set language 'british' -- KO
    select day('2007/01/08 00:00:00') as gg, month('2007/01/08 00:00:00') as mm

    usa invece il il fomato ISO YYYYMMDD HH:MM:SS.CCC che è indipendente dal Language impostato :

    ... assafà paesà

  10. #10
    Utente bannato
    Registrato dal
    Nov 2005
    Messaggi
    112


    scusa ma come faccio a usare il format ISO YYYYMMDD HH:MM:SS.CCC ?

    forse me lo hai anche scritto ma non essendo praticissimo non afferro.

    mi potresti fare un esempio di come fare ?



Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.