Jump to content

SUBIECTE NOI
« 1 / 5 »
RSS
Info Coronavirus/Vaccinare vs Fake News

Nelamurire instalare internet

Cheie licenta Windows11

Sfat plantare arbori pentru o mic...
 rachiu din gemuri si dulceturi

Bara de cautare sa o mut jos?

Accesorii multitool Black and Dec...

Suma maxima.
 Pilonul II - date de piata, tendi...

Geam la baie: va place sau nu va ...

izolație balcon exterior

Izolatie balcon inchis
 Device atasat instalatie PV

Greseala mp - 1/2 - in actul de v...

[CUM] SPV ANAF - Gestionare cont ...

Presiune gaz scazuta
 

Visual Basic - Format Date

- - - - -
  • Please log in to reply
15 replies to this topic

#1
AndiOliver

AndiOliver

    Junior Member

  • Grup: Members
  • Posts: 219
  • Înscris: 27.02.2003
Oricine cunoaste visual basic stie ca putem obtine o data intr-un box prin:
textbox = Date
Ca sa obtinem automat luna putem scrie:
textbox = month(date)

Acum vine intrebarea mea:
Cum scriem automat saptamana?

#2
ezekio

ezekio

    Active Member

  • Grup: Banned
  • Posts: 1,679
  • Înscris: 07.01.2002
Pt. ce vrei tu trebuie sa folosesti functia FORMAT() astfel:

TextBox.text = Format(Date, "ww")

Celelalte formaturi se gasesc la :  "User-Defined Date/Time Formats (Format Function)" in MSDN


Dc ai MSDN-ul  : ;rtfm;

#3
AndiOliver

AndiOliver

    Junior Member

  • Grup: Members
  • Posts: 219
  • Înscris: 27.02.2003
Nu este asa: Codul pe care l-ai scris tu va da numarul saptaminii din an, eu incerc sau scot numarul saptaminii din luna respectiva.

Iar in help-ul msdn am cautat indelung, nu am gasit nimic care sa ma ajute.

#4
ezekio

ezekio

    Active Member

  • Grup: Banned
  • Posts: 1,679
  • Înscris: 07.01.2002
"Citat" din MSDN . Scuze pt. format i-am dat copy/paste .
Nu stiu dc poti sa afli saptamana din luna curenta .


User-Defined Date/Time Formats (Format Function)
      

The following table identifies characters you can use to create user-defined date/time formats:

Character Description
(:) Time separator. In somelocales, other characters may be used to represent the time separator. The time separator separates hours, minutes, and seconds when time values are formatted. The actual character used as the time separator in formatted output is determined by your system settings.
(/) Date separator. In some locales, other characters may be used to represent the date separator. The date separator separates the day, month, and year when date values are formatted. The actual character used as the date separator in formatted output is determined by your system settings.
c Display the date as ddddd and display the time as
ttttt, in that order. Display only date information if there is no fractional part to the date serial number; display only time information if there is no integer portion.
d Display the day as a number without a leading zero (1 – 31).
dd Display the day as a number with a leading zero (01 – 31).
ddd Display the day as an abbreviation (Sun – Sat).
dddd Display the day as a full name (Sunday – Saturday).
ddddd Display the date as a complete date (including day, month, and year), formatted according to your system's short date format setting. The default short date format is m/d/yy.
dddddd Display a date serial number as a complete date (including day, month, and year) formatted according to the long date setting recognized by your system. The default long date format is mmmm dd, yyyy.
w Display the day of the week as a number (1 for Sunday through 7 for Saturday).
ww Display the week of the year as a number (1 – 54).
m Display the month as a number without a leading zero (1 – 12). If m immediately follows h or hh, the minute rather than the month is displayed.
mm Display the month as a number with a leading zero (01 – 12). If m immediately follows h or hh, the minute rather than the month is displayed.
mmm Display the month as an abbreviation (Jan – Dec).
mmmm Display the month as a full month name (January – December).
q Display the quarter of the year as a number (1 – 4).
y Display the day of the year as a number (1 – 366).
yy Display the year as a 2-digit number (00 – 99).
yyyy Display the year as a 4-digit number (100 – 9999).
h Display the hour as a number without leading zeros (0 – 23).
Hh Display the hour as a number with leading zeros (00 – 23).
N Display the minute as a number without leading zeros (0 – 59).
Nn Display the minute as a number with leading zeros (00 – 59).
S Display the second as a number without leading zeros (0 – 59).
Ss Display the second as a number with leading zeros (00 – 59).
t t t t t Display a time as a complete time (including hour, minute, and second), formatted using the time separator defined by the time format recognized by your system. A leading zero is displayed if the leading zero option is selected and the time is before 10:00 A.M. or P.M. The default time format is h:mm:ss.
AM/PM Use the 12-hour clock and display an uppercase AM with any hour before noon; display an uppercase PM with any hour between noon and 11:59 P.M.
am/pm Use the 12-hour clock and display a lowercase AM with any hour before noon; display a lowercase PM with any hour between noon and 11:59 P.M.
A/P Use the 12-hour clock and display an uppercase A with any hour before noon; display an uppercase P with any hour between noon and 11:59 P.M.
a/p Use the 12-hour clock and display a lowercase A with any hour before noon; display a lowercase P with any hour between noon and 11:59 P.M.
AMPM Use the 12-hour clock and display the AMstring literal as defined by your system with any hour before noon; display the PM string literal as defined by your system with any hour between noon and 11:59 P.M. AMPM can be either uppercase or lowercase, but the case of the string displayed matches the string as defined by your system settings. The default format is AM/PM.



#5
AndiOliver

AndiOliver

    Junior Member

  • Grup: Members
  • Posts: 219
  • Înscris: 27.02.2003
Eu am citit enough MSDN, repet nu am vazut nici o posibilitate pentru ca sa obtin numarul saptaminii din luna respectiva. La aceasta ora programele create de mine folosesc input-ul user-ului pentru acest lucru.

#6
menetz

menetz

    Active Member

  • Grup: Members
  • Posts: 1,715
  • Înscris: 08.04.2002
nu are cum sa fie nici o functie sistem.
Dar eu nu inteleg...nu poti imparti la 7 numarul zilei ? :) Chiar sa ceri input de la user pt asa ceva e cam...aberant.

Apropos, conform ISO, prima saptamana din an este considerata prima care contine o zi de marti.

#7
ezekio

ezekio

    Active Member

  • Grup: Banned
  • Posts: 1,679
  • Înscris: 07.01.2002

Quote

Originally posted by menetz
nu are cum sa fie nici o functie sistem.
Nu are cum sa nu fie nici o functie sistem DAR trecem peste asta :D

Quote

Originally posted by menetz

Apropos, conform ISO, prima saptamana din an este considerata prima care contine o zi de marti.
Asa este default dar se poate seta din FORMAT ce zi din saptamana sa fie considerata prima.

#8
menetz

menetz

    Active Member

  • Grup: Members
  • Posts: 1,715
  • Înscris: 08.04.2002
nu are legatura..eu ma referam la calcularea saptamanii din an, cand e nevoie, si care e prima saptamana considerata.

#9
AndiOliver

AndiOliver

    Junior Member

  • Grup: Members
  • Posts: 219
  • Înscris: 27.02.2003
Personal am incercat toate modalitatile posibile, am incercat si asta spusa de tine, care am mai auzit-o si pe un alt forum ( nu spun numele ca sa nu fac reclama gratuita), dar problema este ca nu functioneaza, cel putin nu intotdeauna.
La mine luna se pune automat iar userul nici nu mai are voie sa umble la numarul lunii, daca fac acest lucru si pentru numarul saptamanii din luna respectiva, la fel nu mai las user-ul sa umble nici la aceasta setare, problema este ca imi trebuie un rezultat corect 100% din cazuri.....

#10
aphex

aphex

    New Member

  • Grup: Members
  • Posts: 9
  • Înscris: 31.05.2002
Andi,

a) obtzii numaru' saptamanii pentru data curenta folosind "ww"
creezi o data noua cu ziua de 1 shi luna shi anu' obtzinute prin "mm" shi "yyyy". obtzii numaru saptamanii pentru data asta prin "ww". faci diferentza.
B) nu-mi dau seama inca daca la a) sunt exceptzii care itzi dau calculul peste cap. daca da, ia o metoda mai lunga, dar sigura.
obtzii day-of-week pentru data de 1 a lunii curente (vezi a). extragi din data (potzi shi prin substring) ziua din luna. pe baza  unui algoritm simplist care tzine cont de prima zi a saptamanii (monday/sunday etc) shi cele de mai sus vei obtzine saptamana curenta.

#11
AndiOliver

AndiOliver

    Junior Member

  • Grup: Members
  • Posts: 219
  • Înscris: 27.02.2003
Imi cer scuze pentru intarzierea raspunsului, au existat anumite probleme ce m-au facut sa nu mai accesez forumul pentru ceva vreme.
Sa fiu sincer aphex nu inteleg, in schimb mi-ar fi de ajutor daca ai scrie liniile respective de cod sa le inteleg pe cale empirica.

Multumesc in avans.

#12
Yoda

Yoda

    Eternal padawan

  • Grup: Senior Members
  • Posts: 9,353
  • Înscris: 04.10.2002
O solutie simpla mi se pare a fi parcurgerea urmatorilor pasi:
- afli in ce saptamana a anului se afla ziua de intai a lunii (intA)
- afli in ce saptamana a anului se afla ziua care te intereseaza (intB)
- obtii saptamana din luna aplicand formula: x = intB - intA +1

Exemplu:

Function WeekOfTheMonth(datInput As Date) As Integer
'Returns: The week of the month
'Author: Nic Dobre, [email protected]

Dim d As Date
Dim intWeekNrOne As Integer

d = datInput - DatePart("d", datInput) + 1
intWeekNrOne = DatePart("ww", d)
WeekOfTheMonth = DatePart("ww", datInput) - intWeekNrOne

End Function

#13
aphex

aphex

    New Member

  • Grup: Members
  • Posts: 9
  • Înscris: 31.05.2002
scuza-mi hardcodingu', vb-ul nu este limbaju' meu favorit, daca ai intrebari sau vrei sa extindem codul spune-mi, aici am ilustrat doar algoritmii:

' assumes us date format

Private Sub Form_Load()
    MsgBox CStr(GetWeek1())
    MsgBox CStr(GetWeek2())
End Sub

Private Function GetWeek1() As Integer
    Dim today As Date
    Dim newdate As Date
    Dim w1 As Integer, w2 As Integer
    Dim m As String, y As String
    
    today = Now()
    w1 = CInt(DatePart("ww", today))
    m = CStr(DatePart("m", today))
    y = CStr(DatePart("yyyy", today))
    newdate = DateValue(m & "/1/" & y)
    w2 = CInt(DatePart("ww", newdate))
    
    GetWeek1 = w1 - w2 + 1
End Function

Private Function GetWeek2() As Integer
    Dim today As Date
    Dim newdate As Date
    Dim w As Integer, d As Integer
    Dim m As String, y As String
    
    today = Now()
    m = CStr(DatePart("m", today))
    y = CStr(DatePart("yyyy", today))
    newdate = DateValue(m & "/1/" & y)
    w = CInt(DatePart("w", newdate))
    d = CInt(DatePart("d", today))
    GetWeek2 = Int((w + d - 2) / 7) + 1
End Function

PS:  nostradamnus, daca citeai ce am zis io la a) vedeai ca ai zis ce am zis shi io
PPS: aduna shi tu un "1" la sfarshit, altfel numeri saptamanile incepand de la zero

#14
Yoda

Yoda

    Eternal padawan

  • Grup: Senior Members
  • Posts: 9,353
  • Înscris: 04.10.2002
da aphex, ai dreptate in ambele privinte.

Linia:
   WeekOfTheMonth = DatePart("ww", datInput) - intWeekNrOne

se schimba in:
    WeekOfTheMonth = DatePart("ww", datInput) - intWeekNrOne+1

daca te uiti in algoritm am prevazut asta; la implementare... ce vrei dom'le, caldura mare! ;-)

ai dreptate, ai propus inaintea mea aceasta varianta. Am vazut dupa ce am postat. Prin urmare, acord share de copiright... LOL.

#15
Yoda

Yoda

    Eternal padawan

  • Grup: Senior Members
  • Posts: 9,353
  • Înscris: 04.10.2002
copiright.... hehehe, mai bine ma duc la culcare.

#16
AndiOliver

AndiOliver

    Junior Member

  • Grup: Members
  • Posts: 219
  • Înscris: 27.02.2003
Va multumesc pentru efortul depus in a ma ajuta. Voi incerca sa analizez(invat - pe cit posibil) codul produs de voi si astfel sa-l implementez pentru a-mi rezolva problema.

Anunturi

Chirurgia cranio-cerebrală minim invazivă Chirurgia cranio-cerebrală minim invazivă

Tehnicile minim invazive impun utilizarea unei tehnologii ultramoderne.

Endoscoapele operatorii de diverse tipuri, microscopul operator dedicat, neuronavigația, neuroelectrofiziologia, tehnicile avansate de anestezie, chirurgia cu pacientul treaz reprezintă armamentarium fără de care neurochirurgia prin "gaura cheii" nu ar fi posibilă. Folosind tehnicile de mai sus, tratăm un spectru larg de patologii cranio-cerebrale.

www.neurohope.ro

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Forumul Softpedia foloseste "cookies" pentru a imbunatati experienta utilizatorilor Accept
Pentru detalii si optiuni legate de cookies si datele personale, consultati Politica de utilizare cookies si Politica de confidentialitate