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?
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?
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 . . .
![]()
ormai ci sono dei record mi dice che non puo convertirlo
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:
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.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
lascia testo e riformatta i contenuti così
AAAAMMGGHHNNSS
Non mi piace come suluzione . . .![]()
Fatti degli script Sql che adattano le stringhe . . .
Poi cambi il formato e reimporti le date . . .
argomenta, please. è sempre interessante discutere dei formati delle dateOriginariamente inviato da DarioN1
Non mi piace come suluzione . . .![]()
![]()
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 . . .
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
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.