Pagina 1 di 3 1 2 3 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 23
  1. #1
    Utente di HTML.it L'avatar di KLINKO
    Registrato dal
    Sep 2002
    Messaggi
    285

    "campo testo" con valore "date"

    ho un campo testo dove inserisco al suo interno delle date es. "11/04/2007 8.55.29"

    quando richiamo la select e specifico ORDER by CampoTesto l'ordinamento è sbagliato perchè lo interpreta diversamente

    come posso ovviare al problema?

  2. #2
    O cambi il dato in un datetime direttamente sul DB Sperando che le date sian
    formattate in modo corretto . . .

    Oppure fai il CAST della stringa contenente la data nella clausola ORDER BY , sempre sperando
    che le date sia formattate correttamente . . .


  3. #3
    Utente di HTML.it L'avatar di KLINKO
    Registrato dal
    Sep 2002
    Messaggi
    285
    ormai ci sono dei record mi dice che non puo convertirlo

  4. #4
    Dal punto di vista testuale
    11/05/2007 8:34:11
    viene prima del
    22/01/2007 10:01:33

    Se vuoi usare un campo testuale per le date devi formattare le date in questo modo:
    YYYYMMDDHHNNSS

    Con queste due funzioni fai tutto:
    codice:
    function dateToString(theDate)
    sessionLCID = session.LCID
    	if not sessionLCID = 1040 then
    		session.LCID = 1040
    	end if
    	if not isDate(theDate) then
    		theDate = now()
    	end if
    		theYear = datePart("yyyy",theDate)
    		theMonth = datePart("m",theDate)
    		if theMonth < 10 then theMonth = "0" & theMonth
    		theDay = datePart("d",theDate)
    		if theDay < 10 then theDay = "0" & theDay
    		theHour = datePart("h",theDate)
    		if theHour < 10 then theHour = "0" & theHour
    		theMinutes = datePart("n",theDate)
    		if theMinutes < 10 then theMinutes = "0" & theMinutes
    		theSeconds = datePart("s",theDate)
    		if theSeconds < 10 then theSeconds = "0" & theSeconds
    		dateToString = theYear & theMonth & theDay & theHour & theMinutes & theSeconds
    		session.LCID = sessionLCID
    end function
    
    function stringToDate(theString)
    	if len(theString) = 14 then
    		theYear = left(theString,4)
    		theMonth = mid(theString,5,2)
    		theDay = mid(theString,7,2)
    		theHour = mid(theString,9,2)
    		theMinutes = mid(theString,11,2)
    		theSeconds = right(theString,2)
    			if session.LCID = 1040 then
    				stringToDate = theDay & "/" & theMonth & "/" & theYear
    				theChar = "."				
    			else
    				stringToDate = cInt(theMonth) & "/" & cInt(theDay) & "/" & theYear
    				theChar = ":"					
    			end if
    			stringToDate = cDate(stringToDate & " " & theHour & theChar & theMinutes & theChar & theSeconds)
    	else
    		stringToDate = now()
    	end if
    end function
    la prima converte la data in una stringa del tipo YYYYMMDDHHNNSS mentre la seconda, presa un data nel formato YYYYDDMMHHNNSS la ripristina in una data nel formato normale.

  5. #5
    lascia testo e riformatta i contenuti così

    AAAAMMGGHHNNSS

  6. #6
    Non mi piace come suluzione . . .

    Fatti degli script Sql che adattano le stringhe . . .

    Poi cambi il formato e reimporti le date . . .

  7. #7
    Originariamente inviato da DarioN1
    Non mi piace come suluzione . . .
    argomenta, please. è sempre interessante discutere dei formati delle date

  8. #8
    Che senso ha tenere in formato stringa una data ???

    Nessuno mi vien da dire . . .

    Escludi a priori tutte le funzionalità delle date che il server offre . . .
    E in + ti incasini neglio ordinamenti , confronti etc . . .

  9. #9
    per gli ordinamenti non ti incasini assolutamente (guarda bene il formato suggerito). forse ti perdi qualcosa lato server, da barattare con l'assoluta indipendenza dalle impostazioni internazionali del server. IMHO va ponderata caso per caso

  10. #10
    Formattando una data come stringa nel formato YYYYMMDDHHNNSS puoi fare delle select senza incappare nei problemi delle impostazioni internazionali del server, se italiano o inglese, puoi tranquillamente usare la BETWEEN e con le funzioni MID e LEFT puoi prendere parti delle date a tuo piacimento.

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 © 2025 vBulletin Solutions, Inc. All rights reserved.